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.

Remove comma from string

tsoct
Tera Guru

Hi all,

I have the requirement where the amount in catalogue item must be in format xx,xxxx.xx .... To route the approval base on the amount, I need to remove the comma.

With the script below, it is giving me NaN error. Can anyone help on this?

var Amount0 = current.variables.invoice_amount;
var Amount1 = Amount0.replace(/[^\d.]/g, '');
var Amount2 = Math.round(Amount1);

 

 

1 ACCEPTED SOLUTION

Try this:

var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));

View solution in original post

8 REPLIES 8

Try logging the values. Also try parsing to int:

var Amount0 = current.variables.invoice_amount;
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));

Tried with invoice_amount = 1,909.34

Amount0 return 1,909.34

Amount1 return undefined,

while Amount 2 return NaN

For me that is working:

find_real_file.png

 

Result:

find_real_file.png

Try this:

var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));