Is there a way to _.set a session variable with an expression language value?

I have something like the following:

.exec(Person.Search("Bob")) .exec(_.set("person", "${results.random()}"))

The Person.Search(“Bob”) does a saveAs(“results”), but after that I’m trying to set person to a random one from the results.

The problem is that it’s not interpreting the expression language and instead using the literal value of “${results.random()}”.

I’m struggling to figure out a way I can achieve this (as I need to use person in later steps)

Thanks in advance.

https://gatling.io/docs/current/session/expression_el/#expression-language

Thanks Stéphane, I’ve read this documentation. The expression language does not seem to apply to the _.set method when used like that; can you help explain why it’s the literal value vs. the interpolated value from my other variable that’s in Session?

I was able to get something working by doing the following:

`

import io.gatling.core.session.el._

.exec { session =>
val expr = “${results.random()}”.el[String]
session.set(“person”, expr(session).get)
}

`

Not sure if there’s a way to condense that any more than that or not ¯_(ツ)_/¯