- 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:20 AM
Hi,
For every table created ServiceNow provides an Auto-numbering feature that can be used. All you need is to Configure Table & look for 'Control' tab from the Table.
Thanks,
Jaspal Singh
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎04-09-2020 07:22 AM
Yes,Actually I want through business rule that is the reason I have written script.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎04-09-2020 07:38 AM
In that case don't use parsetInt() use Math.floor(); something like below.
var str_i = Math.floor(str);
Thanks,
Jaspal Singh
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎04-09-2020 07:41 AM
Its not working I have checked it.
