Aka Guglielmo
ServiceNow Employee
ServiceNow Employee

Since I didn't find an OOTB action in the Flow Designer for generating random numbers, I did it by myself.

Attached a PDF that explains how to do it.

 

Enjoy

William

 

 

 
Comments
NMiel
Tera Guru

This worked really well.  I needed to generate a random duration to pass to a Wait for Duration Flow operator.  I added on you script, but kept the original as it makes the Action more versatile for other uses:

(function execute(inputs, outputs) {
  
  var min = Math.ceil(inputs.min);
  var max = Math.floor(inputs.max);
  var result = (Math.random() * (max - min)) + min; //max excluded, min included
  var minutes = Math.floor(result).toString();
  //duration in minutes
  var duration =  new GlideDuration('00:'+minutes+':00');
  
  outputs.resultdecimal = result;
  outputs.resultint = Math.floor(result);
  outputs.resultstring = Math.floor(result).toString();
  outputs.resultduration = duration;
})(inputs, outputs);

find_real_file.png

Version history
Last update:
‎03-02-2020 12:05 AM
Updated by: