I have a test which Posts some items
e.g.
POST:item : 1
POST:item : 2 and so on
and now in 1st Post request, I am trying to set a global variable in pre-request-script
postman.setGlobalVariable("item", 1);
and use this variable in the body e.g
"item": "{{item}}",
it work.
Now in 2nd Post request, I wanted to increment global variable, in pre-request-script
item=item+1;
postman.setGlobalVariable("item", item);
and in body same as above. but its give following error
There was an error in evaluating the Pre-request script: item is not defined
With the current version of Postman (6.2.x), you can set the variables in the Tests tab like
Global Variables
pm.globals.set("variable_key", "variable_value");
Environment Variables
pm.environment.set("variable_key", "variable_value");
To update the answer, it will be
pm.globals.set("item", Number(postman.getGlobalVariable("item"))+1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With