In regards to your question, I am not too sure what you are asking for.
In your last sample, you create a “genRefId” var, and set it as an environment variable. I would imagine then you have your dynamic variable that you are looking for? Then in your environment variable (genRefId), you would see that dynamic value, as pointed out in Sample 2. Every time it executed it would change. Now if you wanted to persist it, you could set it to a new variable everytime in your pm.environment.set().
If you can clarify a bit more exactly what you are expecting, I would be happy to help more.
I am actually looking for a way to generate a unique number and use it in the Request Body. And then, get the whole request body with a generated unique number and set it in a global / environment variable.
Generate unique number in Pre-request Script
Use the unique number in Request Body
{
“referenceId”:“{{genRefId}}”, <---- e.g. 201911141246100
“billerCode”:“PBA”,
“billReferenceNo1”:“1234567”,
“billReferenceNo2”:“”,
“amount”:“3.00”
}
Get the Request Body with the generated unique number
I know what you mean, I want to do the same thing. I need to sign the body, but the body use variables. Eventually I found a solution in the documentation: