Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Round off value in random pin generation

Hareesha
Tera Contributor

Hi all,

I have a requirement to generate Random 6 digit PIN. I have created a flow action and I am able to generate the 6 digit PIN. In Flow designer I have an action to send an Email along with random 6 digit PIN. When I check the flow Its giving me some random 6 digit Number without decimal. But when I check email logs , in email body I can see decimal has been added like if PIN is 144977 instead of its showing '144977.0'  . 

Hareesha_0-1700561769826.png

Hareesha_1-1700561791142.png

 

I have written below script in flow action:

 

(function execute(inputs, outputs) {

// ... code ...

//var random_pin = Math.floor(100000+Math.random()*900000);

var random_pin = Math.round(Math.random() * 1000000);

outputs.pin = random_pin;

})(inputs, outputs);

 

 

Can anyone help me on this. Thanks!

2 REPLIES 2

Neeraj_27
Tera Guru

Hi @Hareesha ,

Try using outputs.pin = parseInt(random_pin) in the above code.

Sonam_Tiwari
Kilo Sage

Hi @Hareesha ,

 

You can simply use transform functions while passing value in email content line below. Select "convert string to number" under string and apply. Thats it.

sonamtiwari_0-1700564352682.png


Hope that helps.
Thanks,
Sonam

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.