- 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 03:07 AM
Hi Lohitha,
is that mean ID and Vendor ID will have same value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 03:18 AM
Do this way,
write a onLoad script,
if(g_form.isNewRecord()){
var num = g_form.getIntValue('<field name>')+1;
incrementNumber = g_form.getValue('number').replace(num,(num+1));
g_form.setValue('<field_name>',incrementNumber );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 03:29 AM
Hi Balaji,
This should be done after the record is submitting.
Thank you,
Lohitha.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 03:16 AM
Hi Lohitha,
If that is the case, what you can do is create a before insert business rule to check the value of last inserted record and split it using Javascript and increment those values in the business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 03:27 AM
Hi Vinoth,
Thank you for your response, I am new to scripting can you tell me how to start with this.
Regards,
Lohitha.