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:
println(session(“locationCode”).as[String])
6b58b338-654b-4f21-b687-b5c0cd5ad86b.6f2cf91d-6b62-4f41-84c0-ed0a6e3231ca.f%3A5880307d-8f91-44aa-8301-24af36b57320%3A9e1929d6-384f-4e94-a93a-6b4c2f5c3ccb

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”)
.post("/login/v1/sandbox/login?session_code=xxx&execution=yyy&client_id=9e1929d6-384f-4e94-a93a-6b4c2f5c3ccb&tab_id=$zzz")
.headers(headers_login)
.formParam(“username”, “ffdcuser1”)
.formParam(“password”, “123456”)
.check(headerRegex(“Location”, “code=(.*)”).saveAs(“locationCode”))
.check(status.is(200)))
.exec(session => {
properCode = session(“locationCode”).as[String].replaceAll("%3A",":")
session})
.exec(http(“1.3.2 - Openid Config”)
.post("/login/v1/sandbox/oidc/token")
.disableFollowRedirect
.headers(headers_token)
.formParam(“scope”, “code”)
.formParam(“code”, properCode)
.check(status.is(200)))

}

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