doIfEqualsOrElse in ElFileBody

Hello everybody,
I am newbie to Gatling and Scala and I need a little help with conditional bahaviour inside ElFileBody.
What I would like to do is to load different files based on a certain condition. Here’s my block of code:

val scnNavigation = scenario(“Perform Navigation”)
.repeat(1) {
feed(csvFeederNavigation)
.exec {
doIfEqualsOrElse("${httpMethod}", “POST”) {
exec (http("${controller} → ${action}")
.post("${controller}/${action}?bankSrgKey=${bankSrgKey}&customerId=${customerId}&paramId=${paramId}&paramType=${paramType}")
.headers(Map(
“Content-Type” → “application/json;charset=UTF-8”,
“Origin” → “http://erm-eca-04”,
“uniqueUserRoleToken” → “${uniqueUserRoleToken}”,
“userSessionToken” → “${userSessionToken}”)
)
.body(
ElFileBody(“bodies/Navigation/${BANK_ID}${paramId}${action}.json”)
)
.check(status.is(200))
.check(bodyString.saveAs(“responseBody”))
).exec { session => println(session(“responseBody”).as[String]); session}
} {
exec (http("${controller} → ${action}")
.get("${controller}/${action}?bankSrgKey=${bankSrgKey}&customerId=${customerId}&paramId=${paramId}&paramType=${paramType}&stepId=${stepId}&roleId=${roleId}&subworkflowId=${subworkflowId}&workflowId=${workflowId}&functionCode=${functionCode}&functionalityId=${functionalityId}&isDeliberating=${isDeliberating}&lvl=${lvl}")
.headers(Map(
“uniqueUserRoleToken” → “${uniqueUserRoleToken}”,
“userSessionToken” → “${userSessionToken}”)
)
.check(status.is(200))
.check(bodyString.saveAs(“responseBody”))
).exec { session => println(session(“responseBody”).as[String]); session}
}
}
}

I need to change the line in bold and to have something like this (the following code throws a type mismatch exception):
.body(
doIfEqualsOrElse("${action}", “GetStepBaseData”) {
val pathFile = “bodies/Navigation/${BANK_ID}${paramId}${stepId}.json”
ElFileBody( pathFile )
} {
val pathFile = “bodies/Navigation/${BANK_ID}${paramId}${action}.json”
ElFileBody( pathFile )
}
)

How can I achieve it?
Thanks in advance,
Matteo

No, that’s not how you should do things.
You should pass a function to ElFileBody where you would compute the correct path.

ElFileBody(session => “whatever string”)

https://gatling.io/docs/current/session/session_api/

Thank you very much, I will give it a try.
Another question: how can I print “responseBody” only if the status is different from 200?

Thanks in advance,
Matteo

No, please don’t ask “another question” in a thread where the question has been answered.
Other people will search the archives to help or look for help and will consider the thread title.
Please create a new thread.