# how to assign response value to next request

**URL:** <https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619>\
**Category:** Gatling (Open-Source)\
**Created:** [October 31, 2014, 2:05pm UTC](https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619 "2014-10-31T14:05:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anitha\_Thalasila](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Anitha\_Thalasila](https://community.gatling.io/u/Anitha_Thalasila)\
**Post date:** [October 31, 2014, 2:05pm UTC](https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619/1 "2014-10-31T14:05:58Z")

</div>

Hi All,

In below code, i am capturing response in **UserId** variable. I am failing to pass this **UserId** variable in next request, it is throwing errors.

.exec(http(“Create USer”)  
.post(""“Urlxxxx”"")  
.body(StringBody("""{“email”:“[sample@gmail.com](mailto:sample@gmail.com)”}"""))  
.check(headerRegex(“Location”, “(.\*)”).saveAs(“userId”))) // capturing dynamic value in UserId variable

// System.out.println("UserID: " + userId+ “\n”) // i tried to print like this, no use

//exec(  
(s:Session) =\> println(s.getAttribute("  
userId")) // tried this also, but no use to conform what i am getting in UserId  
)

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* next request\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

val scn1 = scenario(“Identity”)  
.exec(http(“request\_0”)  
.post("""/urlxxxx""")  
.body(StringBody("""{  
“username”:“anitha156”,  
“password”:“anitha56”,  
“userId”:"${userId}", // passing that userid in this request.  
}""")))

}

Can anyone please help me on this?

Thanks in advance…

Regards,  
Anitha.

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [October 31, 2014, 2:30pm UTC](https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619/2 "2014-10-31T14:30:01Z")

</div>

Except if you disabled followRedirect, you’ll never see Location headers, so your headerRegex won’t work.  
Use currentLocationRegex instead. [http://gatling.io/docs/2.0.1/http/http\_check.html?highlight=currentlocation#page-location](http://gatling.io/docs/2.0.1/http/http_check.html?highlight=currentlocation#page-location)

---

<div class="post-metadata">

**Author:** ![Anitha\_Thalasila](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Anitha\_Thalasila](https://community.gatling.io/u/Anitha_Thalasila)\
**Post date:** [November 3, 2014, 7:26am UTC](https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619/3 "2014-11-03T07:26:40Z")

</div>

Hi Stephane,

Thank you for your reply…

When i used ".check(currentLocationheaderRegex(“Location”, “(.\*)”).saveAs(“userId”)))"i got below error message.

[ERROR] i.g.a.ZincCompiler$ - C:\Users\anitha\Desktop\gatling-chart  
s-highcharts-2.0.1\user-files\simulations\CreateUser.scala:128: too many arg  
uments for method apply: (v1: io.gatling.core.session.Session =\> io.gatling.core  
.validation.Validation[String])io.gatling.http.check.url.CurrentLocationRegexChe  
ckBuilder[String] with io.gatling.http.check.url.CurrentLocationRegexOfType in t  
rait Function1

In documentation i saw below syntax , if i use this , where should I save my **userId** value?

```auto
__currentLocationRegex("http://foo.com/bar?(.*)=(.*)").ofType[(String, String)]__

And one more point here, i am trying to pass this value to next request in same script, like ,"{userId}", But i am getting "No attribute name userId is found.

So, can you please help me on how to pass this value to next request?

Thanks for your help in advance.
Regards,
Anitha. 

```

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [November 3, 2014, 9:46pm UTC](https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619/4 "2014-11-03T21:46:59Z")

</div>

Please properly read the documentation.

```auto
__currentLocationRegex("[http://foo.com/bar?(.*)=(.*)](http://foo.com/bar?(.*)=(.*))")__

```

Not currentLocationheaderRegex( **"\*\*\*\*Location"** , “(.\*)”)

---

<div class="post-metadata">

**Author:** ![Tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Tom](https://community.gatling.io/u/Tom)\
**Post date:** [June 27, 2017, 11:19am UTC](https://community.gatling.io/t/how-to-assign-response-value-to-next-request/1619/5 "2017-06-27T11:19:17Z")

</div>

I found answer for the not answered part of the question (how to capture more than one regex group and pass it to further code) in another group: [https://groups.google.com/d/msg/gatling/yvGxQKkKzsA/O8bQ6JJcoF0J](https://groups.google.com/d/msg/gatling/yvGxQKkKzsA/O8bQ6JJcoF0J) . Examples on how to use Tuples in Scalal: [http://alvinalexander.com/scala/scala-tuple-examples-syntax](http://alvinalexander.com/scala/scala-tuple-examples-syntax). The way described there should be already implemented for Gatling ([https://github.com/gatling/gatling/issues/1991](https://github.com/gatling/gatling/issues/1991)), but I was not able to make it work with Gatling 2.2.2.  
I am posting reply to this old group for future users looking for a solution who might find it useful.
