How to pass value between two scenarios in gatling?

Hi,

I have two scenarios in my script. I want to pass value of “CreateId” to 2nd scenario. I have saved “CreateId” in 1st scenario.

Error says:

No attribute named ‘CreateId’ is defined

jsonPath($.id).find(0).exists, found nothing

Scenario - 1

val create = scenario("Create")
        .exec(http("post_request_create")
        .post("/api/asdf")
        .headers(headers_10)
        .body(StringBody(session =>s"""{"name": "${randomName()}"}""")).asJSON
        .check(jsonPath("$.id")
        .saveAs("CreateId"))
        )

Scenario - 2

val addTerm = scenario("Add Term")
        .repeat (repeatCount){
        exec(http("Add")

        // NOT WORKING
            //.post("""/api/asdfg/${thesaurusid}/terms""")

        // NOT WORKING
            .post(session => "/api/asdfg/" + session.get("CreateId").asOption[String] + "/terms")

            .headers(headers_10)
            .body(StringBody(session =>s"""{...somedata...}"""))
            )
        }
val scn = List(create.inject(atOnceUsers(1)),addTerm.inject(nothingFor(10 seconds), atOnceUsers(userCount)))
setUp(scn).protocols(httpProtocol)

Tried with below code and it worked. Hope it helps others.

var CreateId = ""

Scenario - 1

val create = scenario("Create")
        .exec(http("post_request_create")
        .post("/api/asdf")
        .headers(headers_10)
        .body(StringBody(session =>s"""{"name": "${randomName()}"}""")).asJSON
        .check(jsonPath("$.id")
        .saveAs("CreateId"))
        )

        .exec(session => {
            CreateId = session("CreateId").as[String].trim
            println("%%%%%%%%%%% ID =====>>>>>>>>>> " + CreateId)     
            session}       
        )

Scenario - 2

val addTerm = scenario("Add Term")
    .exec(_.set("CreateId", CreateId)) // Set it here
       .repeat (repeatCount){
        exec(http("Add")
       .post("""/api/asdfg/${CreateId}/terms""")
       .headers(headers_10)
       .body(StringBody(session =>s"""{...somedata...}"""))
            )
        }
val scn = List(create.inject(atOnceUsers(1)),addTerm.inject(nothingFor(10 seconds), atOnceUsers(userCount)))
setUp(scn).protocols(httpProtocol)