Auto Numbering

Kumar38
Kilo Sage

I need to Populate Correlation ID on a Custom Table with numbers starting from 400000 and Incremented by 1 and If Possible need to Validate If number already exists.

Tried : javascript: global.getNextObjNumberPadded();

How Do I do this?

8 REPLIES 8

I tried this and its working fine. How do I confirm enabling that Property causes any effect on the existing FUnctionalities/ Work?

I do not think, it will cause any problem on existing functionalities/ Work, the new property will be in effect when you enabled it.

Adding to Shishir, Enabling this property can auto assign the number on any table onsubmit instead of onload.

Thanks.

Neeraj Sharma10
Tera Guru

Also,  javascript:getNextObjNumber();
Generate a unique number every time a form is loaded and if not saved it will skip the last generated number.

You can use below before BR to overcome this problem

 

(function executeRule(current, previous /*null when async*/) {
var curr_max_num=10000000;
var next_num=0;
var gr = new GlideRecord('Custom Table Name');
gr.addQuery('Field Name','CONTAINS','NUM');
gr.query();
while(gr.next())
{
var max_str=gr.'Field Name';
var array = max_str.split('M');
var recnum=parseInt(array[1]);
if(recnum>curr_max_num)
curr_max_num= recnum;

}
var nxt_val=curr_max_num+1;
var nxt_val_str='NUM'+nxt_val;
current.'Field Name'=nxt_val_str;
})(current, previous);

 

Thanks 

Neeraj