Hi All, I am newman here.
how can I have a same random integer in two tags in the body ?
for example:
{
"rollnumber" : "{{randomInt}}",
"studentNumber" : "{{randomInt}}"
}
I want to have a same random integer in both rollnumber and studentNumber
how to do that ?
bpricilla
(Pricilla B)
2
@brahmajitammana Welcome to the community 
Under your pre-request script you need to assign the random variable to a specific variable (scope can be based on your req).
Under prerequest script, please paste this:
pm.environment.set('int', pm.variables.replaceIn('{{$randomInt}}'));
Now you can use the variable int in both places
{
"rollnumber" : "{{int}}",
"studentNumber" : "{{int}}"
}
Hope this solves your issue :blush:
1 Like
In your pre-request script you can set a random number to a variable then use that variable in the body of your request.
Pre-request
const myRandomInteger = Math.floor(Math.random() * 1000);
pm.variables.set('myRandomInteger', myRandomInteger);
Body
{
"rollnumber" : {{myRandomInteger}},
"studentNumber" : {{myRandomInteger}}
}
2 Likes