Hi @dchiesa1 ,
I have created a mock in Apigee which should send back a random serial number of length 8.
Code:
context.setVariable("serialNumber",(Math.floor(Math.random() * 90000000)));
Output(Number in exponential format):
"serialNumber": "3.7680179526860476E7",
Output I need: 37680179
Can you please help?
Solved! Go to Solution.
You can get want you want simply by converting to string.
context.setVariable("serialNumber",(Math.floor(Math.random() * 90000000)).toString());
And as a bonus, you can inline using the Source element
<Javascript continueOnError="false" enabled="true" timeLimit="200" name="JS-random">
<Source>context.setVariable("serialNumber",(Math.floor(Math.random() * 90000000)).toString());</Source>
</Javascript>
You can get want you want simply by converting to string.
context.setVariable("serialNumber",(Math.floor(Math.random() * 90000000)).toString());
And as a bonus, you can inline using the Source element
<Javascript continueOnError="false" enabled="true" timeLimit="200" name="JS-random">
<Source>context.setVariable("serialNumber",(Math.floor(Math.random() * 90000000)).toString());</Source>
</Javascript>
Thank you, @kurtkanaskie!