Incident numbering

Michael Bachme1
Kilo Guru

We noticed recently that our Incident numbers have grown beyond the halfway point of six-figures. What happens when our Incident number reaches 999999? Do we roll into 1000000?

1 ACCEPTED SOLUTION

When you get to the end of your six digit numbering, the incident that follows INC999999 is INC1000000. The number will continue, it will just be a little longer.


View solution in original post

11 REPLIES 11

Hi Chuck,

 

Yes, I changed the number from 6 to 7 but I am not able to sort by Number field.

 

If you order ascending, you will end up with a list of tickets starting with the tickets created most recent after the 1,000,000 mark… and over time the current tickets will just get further and further away. And if you order the view descending, you will end up with "INC1…" at the end of your list which isn't helpful either. 

 Thanks,

Neeta Patil

You'll need to renumber all the old records then. I remember doing this years ago when I was a customer. The script went something like this - note, you'll want to test this in scripts - background first on a few DEV records (which is why the setLimit(5) is in there). For a million records, this could take a while.

var incGr = new GlideRecord('incident');
incGr.setLimit(5);
incGr.query();

while (incGr.next()) {
	incGr.setWorkflow(false);
	incGr.autoSysFields(false);
	incGr.forceUpdate(true);
	
	incNum = incGr.getValue('number');
	incNum = incNum.replace('INC', ''); // strip off the INC
	
	var newNum = pad(incNum, 7); // Make a 7 digit count w/padded 0s
	inc.number = 'INC' + newNum;
	inc.update();
}

function pad(n, width, z) {
  z = z || '0';
  n = n + '';
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}