How to modify the response from a previous request and pass it to the next request?

I want to replace a part of the response and pass it to the next request as a form parameter. How do I do it?

here is a part of the response that I capture in a session variable called locationCode
.check(headerRegex(“Location”, “code=(.*)”).saveAs(“locationCode”))

The resulting string is as follows:

Now I want to replace ‘%3A’ with ‘:’ and put it back in session and use it as a form parameter. I have pasted the relevant part of the code. But it’s not working. The variable properCode is not getting updated and passed to second request.

var properCode: String = “”
val scn = scenario(“RetrieveAccountInfo”).repeat(iCnt) {
exec(http(“1.1 - Launch”)
.formParam(“username”, “ffdcuser1”)
.formParam(“password”, “123456”)
.check(headerRegex(“Location”, “code=(.*)”).saveAs(“locationCode”))
.exec(session => {
properCode = session(“locationCode”).as[String].replaceAll("%3A",":")
.exec(http(“1.3.2 - Openid Config”)
.formParam(“scope”, “code”)
.formParam(“code”, properCode)


The Gatling DSL specifies a sequence of builders that are executed at startup. At this point, ‘properCode’ will be empty

After you do the manipulation of locationCode, you need to save the result into a session variable rather than a scala val