- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2020 07:14 AM
How to write a script for auto numbering records through business rule.I have written below script but it is not triggering.
var gr= new GlideRecord('table_name');
gr.orderByDesc('field_name');
gr.query();
if(gr.next())
{
var num= gr.field_name;
var str= num.substring(3);
var str_i = parseInt(str);
str_i++;
gr.num="CI"+str_i;
}
Can you please suggest me
Solved! Go to Solution.
- Labels:
-
Continual Improvement (CIM)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2020 07:48 AM
Try below in background script before updating the same in business rule. Also, your business rule is on which table & when it is executing makes difference.
var gr= new GlideRecord('incident');
gr.orderByDesc('number');
gr.query();
if(gr.next())
{
var num= gr.number;
var str= num.substring(3);
gs.print(str);
var str_i=Math.floor(str)+1;
gs.print(str_i);
gr.num="CI"+str_i;
gs.print(gr.num);
}
Let me know until what step you get values printed properly in background script.
Thanks,
Jaspal Singh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2020 07:48 AM
Try below in background script before updating the same in business rule. Also, your business rule is on which table & when it is executing makes difference.
var gr= new GlideRecord('incident');
gr.orderByDesc('number');
gr.query();
if(gr.next())
{
var num= gr.number;
var str= num.substring(3);
gs.print(str);
var str_i=Math.floor(str)+1;
gs.print(str_i);
gr.num="CI"+str_i;
gs.print(gr.num);
}
Let me know until what step you get values printed properly in background script.
Thanks,
Jaspal Singh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2020 07:22 AM
Hi,
Try with adding gr.update() at the end.
You can refer below link it will help,
Kindly mark the answer as Correct and Helpful if this answers your question.
Thank You.
Regards,
Geetanjali Khyale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2020 07:23 AM
I have added gr.update(); but it is not triggering the number