How to increment a field number value using Business Rule instead of Number maintenance.

Sherine
Kilo Explorer

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

10 REPLIES 10

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);

 

 

 

 

Hi,

you should increment 001 and it should become 002

please enhance the script accordingly

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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);

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);

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader