Reset table auto numbering by script

Wade Clairmont
Tera Guru

Hey all,

There has to be someone out there that has done this, it seems fairly straight forward, but eludes this guy!

I have a custom table, requiring custom auto numbering.   Basically "Current year - incremented #".

However,   I need to automatically reset the incremented # when the current year changes.

The incremented # is the table auto num with no prefix, so that might add another level, maybe not.

Thanks in advance.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Wade,



Keep track of your record number in a separate table. You COULD use the sys_number_counter table.



Write yourself a script that gets that number and prefixes with the current year. E.g. 20170001.



Write a BR that runs on query of that table so each time it reads, it first checks if the year has changed and number needs to be reset. If so, update the number and continue to read the new values going forward. GlideDate() is going to come in to play here.



Reference:


Business Rules - ServiceNow Wiki


Business Rules Best Practices - ServiceNow Wiki  


View solution in original post

1 REPLY 1

Chuck Tomasi
Tera Patron

Hi Wade,



Keep track of your record number in a separate table. You COULD use the sys_number_counter table.



Write yourself a script that gets that number and prefixes with the current year. E.g. 20170001.



Write a BR that runs on query of that table so each time it reads, it first checks if the year has changed and number needs to be reset. If so, update the number and continue to read the new values going forward. GlideDate() is going to come in to play here.



Reference:


Business Rules - ServiceNow Wiki


Business Rules Best Practices - ServiceNow Wiki