Unable to retrieve session variable "lastout"

.doWhile(session => session(“growing”).as[Boolean].equals(true) && session(“counter”).as[Int].<(20), “counter”) {
pace(1)
.feed(trackFeeder)
.exec(api.StoreStream.reqGetStreamScs("${clipId}", “${authToken}”)
.check(checkIf((response: Response, session) => response.status.code == 200) {
jsonPath("$.tracks."+ session(“trackid”).as[String] + “.representations…bandwidth”).findAll.optional.saveAs(“bitrates”)
jsonPath("$.tracks."+ session(“trackid”).as[String] + “.segments[-1:].out”).find.optional.saveAs(“lastout”)
jsonPath("$.tracks."+ session(“trackid”).as[String] + “.segments[-1:].step”).find.optional.saveAs(“laststep”)
printConsoleLog(s"Get first stream"+ “${clipId}” + “${trackid}” + “${lastout}” + “${laststep}”, “INFO”)
jsonPath("$.growing").find.saveAs(“growing_data”)
})
)
.exec { session =>
doIf(session => session(“lastout”).asOption[Int].isDefined) {
val lastmoof = (session(“lastout”).as[Int] - session(“laststep”).as[Int]).asInstanceOf[String]
printConsoleLog(s"moof"+ “${clipId}” + “${trackid}”+ “${bitrate}”+ lastmoof, “INFO”)
foreach("${bitrates}", “bitrate”) {
// change to get stream by track id, bitrate, last moof
exec(api.StoreStream.reqGetStreamMoof("${clipId}","${trackid}","${bitrate}", lastmoof, “${authToken}”))
}
}
session.remove(“bitrates”).remove(“lastout”).remove(“laststep”)
session
}
}

I not quite understand why it does not pick up the session variable “lastout” when i did a save on the do while session.

It keeps returning an error.

SessionHookBuilder$$anon$1 - ‘hook-3’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘lastout’ is defined’, forwarding to the next one
12:11:22.857 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-3’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘lastout’ is defined’, forwarding to the next one
12:11:23.890 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-3’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘lastout’ is defined’, forwarding to the next one
12:11:24.914 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-3’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘lastout’ is defined’, forwarding to the next one
12:11:25.924 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-3’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘lastout’ is defined’, forwarding to the next one

Can someone help me on this ? really appreciated.

Please check what you can and cannot do in an exec(function) block: https://gatling.io/docs/gatling/reference/current/general/scenario/#exec