Trying to script in a workflow activity to get random number to use in timer

jlaps
Kilo Sage

I have a particular workflow that is getting triggered to close to other instances of itself, and its causing problems where some of the steps are still in process from other instances, so I am trying to space them out in the workflow. I am trying to generate a random number between 0-10, and then will multiply that by 60 to get however many minutes to set the wait timer to. However,  I am having trouble with the syntax and am looking for some help.

 

var workflow.scratchpad.wait = Math.floor(Math.random() * (10 - 0)) + 0;

 

I am getting an incomprehensible error from this line, and need some help on formatting, or otherwise getting some randomness I can use. Thanks!

jeff

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jlaps 

try this logic

workflow.scratchpad.wait = Math.floor(Math.random() * 11) * 60;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@jlaps 

try this logic

workflow.scratchpad.wait = Math.floor(Math.random() * 11) * 60;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader