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

Hi,

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

.body(ElFileBody(“ProjectName/0002_request.json”))

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.