How to increment a field number value using Business Rule instead of Number maintenance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2021 10:23 PM
Hi All,
I have a string field, number, which populate the value as "ABC001'. When a new record is created I want the number field to be incremented to 'ABC002'.
Initially, I did use the number maintenance concept, but in some scenarios, the functionality is breaking.
Please advise on how to proceed.
Thanks in advance.
Regards,
Sherine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2021 09:37 PM
Hi Ankur,
Tried below script returning NAN
function get_numbers(input) {
return input.match(/[0-9]+/g);
}
var string = '001';
var first_test = get_numbers('string');
first_test = parseInt(first_test) +1;
gs.print(first_test);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2021 04:57 AM
Hi,
you should increment 001 and it should become 002
please enhance the script accordingly
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2021 05:12 AM
Hi Ankur ,
I tried this in background script and it gives me 2 expected is 002
function get_numbers(input) {
return input.match(/[0-9]+/g);
}
//var string = '001';
var first_test = get_numbers('001');
first_test = parseInt(first_test ) +1;
gs.print(first_test);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2021 09:30 AM
Hi Ankur,
i tried below code it gives me 2 instead of 002
function get_numbers(input) {
return input.match(/[0-9]+/g);
}
//var string = '001';
var first_test = get_numbers('001');
first_test = parseInt(001) +1;
gs.print(first_test);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2021 01:35 AM
So that is what I mentioned once you get the incremented value you need to determine the sequence was starting with 00 or only 0 based on the integer value
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader