- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 12:24 AM
We have a string field called ‘sum’ in ServiceNow that sometimes contains numeric data (e.g. ‘10000’) and sometimes contains non-numeric text (like ‘No limit’).
We want to permanently store numeric values with thousands separators so that ‘10000’ becomes ‘10 000’ in all ServiceNow views. However, we want to skip records that are ‘No limit’ or other non-numeric text.
How can I write a run a Business Rule to parse, format, and update only the numeric records while leaving the special text unchanged, and ensure a space is always used as the thousands separator?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 02:16 AM
if the value is not from above then use parseInt() and store the integer value
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 01:02 AM
Hi @sondrefaane
Try executing below script in BR.
Condition of the BR should be whenever you want the script to run.
function numberWithCommas(x) {
var num_regex = '^[0-9]*$';
if(x.match(num_regex)){
var num_parts = x;
num_parts = num_parts.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return num_parts;
}
else{
return false
}
}
var separated_value = numberWithCommas(current.<your field name>);
if(separated_value != false){
current.<your field name> = separated_value;
//current.update() --- uncomment this if you are using an after update BR
}
If my answer has helped you in any way please mark it correct or helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 01:57 AM
why not make that as integer field?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 02:04 AM
Because it also stores values like "No limit" or "Per Contract". It's a field describing purchasing power for a commitment connected to a role. Found a solution, but thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 02:16 AM
if the value is not from above then use parseInt() and store the integer value
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader