- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 04:47 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:46 AM
Try this:
var Amount0 = current.variables.invoice_amount.toString();
var Amount1 = Amount0.replace(/[^\d\.]/g, '');
var Amount2 = Math.round(parseInt(Amount1));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 04:49 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 04:50 AM
Use the following solution instead, it should work:
https://www.servicenowelite.com/blog/2015/5/5/remove-commas-from-a-string-field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 05:13 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2020 06:21 AM
Tried and it's still giving NaN..