The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Sync number counters

Justin Abbott
Giga Guru

Requirement: Have multiple tables use the 'REQ' prefix for ticket numbering and keep the number counters in sync to prevent duplicates.

We have three tables, sc_request, u_reqc_software_request, and u_reqc_nonuser_setup_request, that need to all use the same number prefix, REQ. Through number maintenance I have accomplished this and set them all to use the same number and number counter. These number counters are not staying in sync, however.

For example, if the number counters are:

sc_request: 1,425,037

u_reqc_software_request: 1,425,037

u_reqc_nonuser_setup_request: 1,425,037

and then I insert 2 new records on u_reqc_software_request, the number counters are:

sc_request: 1,425,037

u_reqc_software_request: 1,425,039

u_reqc_nonuser_setup_request: 1,425,037

Is there a way to configure the number maintenance/number counters so that these numbers can sync up?

1 ACCEPTED SOLUTION

Thanks for the response, Mike. You helped me think about this in a different way, which led me to a different solution.



I copied the out-of-the-box 'getNextObjNumberPadded' global business rule and modified it into a script include that can be used as an alternative. My custom version accepts a table name as a parameter. Instead of using the record's table name to pass to the NumberManager(), it passes the table name.



I used dictionary overrides to set the default values for number to 'javascript:uGetNextObjNumberPadded('sc_request');', for example, so that the tables use the same Number Maintenance.



function uGetNextObjNumberPadded(table) {


  if (table) {


          var assignOnInsert = gs.getProperty("glide.itil.assign.number.on.insert");


          if (assignOnInsert == 'true') {


          if (current.sys_id.isNil())


          return null;


  }



  var nm = new NumberManager(table);


  return nm.getNextObjNumberPadded();


  }


}


View solution in original post

2 REPLIES 2

Mike Allen
Mega Sage

I would bet that you could put a business rule on the table that says, before update:



var num = new GlideRecord('sys_number');


num.addQuery('sys_id', 'IN', '<3 sys_ids for the numbers you want to synch>';


num.query();


var max = 0;


while(num.next()){


        if(num.number > max){


                  max = num.number;


        }


}



num.initialize();


num.addQuery('sys_id', 'IN', '<3 sys_ids for the numbers you want to synch>';


num.query();


while(num.next()){


        num.number = max;


        num.update();


}


Thanks for the response, Mike. You helped me think about this in a different way, which led me to a different solution.



I copied the out-of-the-box 'getNextObjNumberPadded' global business rule and modified it into a script include that can be used as an alternative. My custom version accepts a table name as a parameter. Instead of using the record's table name to pass to the NumberManager(), it passes the table name.



I used dictionary overrides to set the default values for number to 'javascript:uGetNextObjNumberPadded('sc_request');', for example, so that the tables use the same Number Maintenance.



function uGetNextObjNumberPadded(table) {


  if (table) {


          var assignOnInsert = gs.getProperty("glide.itil.assign.number.on.insert");


          if (assignOnInsert == 'true') {


          if (current.sys_id.isNil())


          return null;


  }



  var nm = new NumberManager(table);


  return nm.getNextObjNumberPadded();


  }


}