How to get access to gatling session var for use in other scala function

Hi, I’m trying to figure out how to get access to a session var for later use in a scala function. I’ve searched through the forum and I’ve tried the following with no success. What do I need to do?

`

  var mId = ""
    
  val scn = scenario("ReadLogs")
    .exec(http("Some Request")
      .get("/somepath")
        .check(jsonPath("$.id").findAll.saveAs("myId")))
    .exec(session => {
      mId = session.get("myId").as[String]
      println("My Id: " + mId )
      session
    })
  
  def someFunction(): Unit = {
    //do something with mId
  }

`

What does the following print?`

 println("My Id: " + mId )

`
if it is only My Id: then your jsonPath is wrong. Test it here https://jsonpath.curiousconcept.com/

Within the session block it correctly prints the id I expect. The var is getting saved to the session correctly, so that’s not the issue. The issue is that outside of that block, in someFunction mId is back to being “”. How can I access the value that I set within the block in a scala function?

You should be able to get the value by using mId, if you have declared it globally.