- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 01:56 AM
Hi All,
I have a string field (vendor) which needs to be incremented with a value(V-001 so on) this should be generated when ever a new record is created.
Please let me know how I can achieve this?
Regards,
Lohitha.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 04:10 AM
Hi Lohitha,
Use the below script to extract the number from the vendor field and you have to pass the last created record of your custom table. I have tried the below script to extract the number and it was working and you have to try similar as below.
function get_numbers(input) {
return input.match(/[0-9]+/g);
}
var m = new GlideRecord('table_name');
m.orderByDesc('sys_created_on');
m.query();
if(m.next())
{
var string = m.vendor;
var first_test = get_numbers('string');
first_test = parseInt(first_test) +1;
gs.print(first_test);
current.vendor = "value of prefix" + first_test;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 02:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 02:12 AM
Yes, This will help:
Managing Record Numbering - ServiceNow Wiki
thanks
note: please hit helpful/correct depending upon the impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 02:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 03:04 AM
Hi All,
vendor
My issue is not with the number maintenance, I have two fields One is ID and other is vendor ID which act as serial numbers. They need to get auto incremented when ever a new record is created. If I use auto number as you have mentioned I get ID as 1 and vendor ID as 2 and when another record is created ID is 2 vendor ID is 4.
My output should be independent of other fields.
Regards,
Lohitha.