how to assign response value to next request

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”)
.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

(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”)
“userId”:"${userId}", // passing that userid in this request.


Can anyone please help me on this?

Thanks in advance…


Except if you disabled followRedirect, you’ll never see Location headers, so your headerRegex won’t work.
Use currentLocationRegex instead.

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
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?

__currentLocationRegex("*)=(.*)").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.

Please properly read the documentation.


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

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: . Examples on how to use Tuples in Scalal: The way described there should be already implemented for Gatling (, 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.