Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

Willem
Giga Sage

Have you tried without the . in line 2 (any character except newline).

Like this:

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

Alberto Consonn
ServiceNow Employee

Use the following solution instead, it should work:

https://www.servicenowelite.com/blog/2015/5/5/remove-commas-from-a-string-field

 

Willem
Giga Sage

Or if your intention is to not replace the . use the following:

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

Tried and it's still giving NaN..