How to pass the variable defined in scala to the JSON file using ElFileBody command


We are defining the variable using def at global level and trying to pass this value as parameter in the json using ElFileBody command, but its not working.

def parameter=

Inside exec used the below command


in the above request, replaced the json content with ${parameter}.

While executing am getting error as parameter variable not found

Please help on this issue.

This is not how Gatling Expression Language works.
It replaces placeholders with matching Session attribute’s value.
It can’t be used to call a method.

What you can do if first is to push a new Session attribute:

.exec(session -> session.set("parameter", parameter))

Thanks for your reply.