Get Next Incremental Number skipping values

Katie A
Mega Guru

Hello, I have a Business Rule on the CMDB CI Computer table that will create a new asset tag "BEFORE" "INSERT".

I noticed that the auto-number counter is SKIPPING values. It starts at 30,000 and creates the new asset tag but it only creates even-numbers. So it started at 30,000 and the next one was 30,0002 and the next was 30,0004 and 30,0006 etc.

I have tested this by creating a bunch of new computers and each time it SKIPS the next odd number and jumps ahead to the next even number.

What could be the issue?

function onBefore(current, previous) {

  //Set asset tag incremental number maintenance counter on Configuration Item table

  current.asset_tag = getNextObjNumberPadded();

}

Screen Shot 2016-05-11 at 11.54.53 AM.png

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,



By default, numbers are generated every time a new record is created. When records are created but not saved, a gap in the numbering is created. To generate numbers only when records are saved, navigate to System Properties > System and set the property Assign a task number only upon insert (prevents unused numbers) to true


http://wiki.servicenow.com/index.php?title=Managing_Record_Numbering#Preventing_Numbering_Gaps.


View solution in original post

13 REPLIES 13

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,



By default, numbers are generated every time a new record is created. When records are created but not saved, a gap in the numbering is created. To generate numbers only when records are saved, navigate to System Properties > System and set the property Assign a task number only upon insert (prevents unused numbers) to true


http://wiki.servicenow.com/index.php?title=Managing_Record_Numbering#Preventing_Numbering_Gaps.


Thank you. I did try this but it is still skipping values unfortunately.


Community Alums
Not applicable

Try async or after. I had similar issues with the system trying to create duplicates setting a field with a before BR before.


NO NO NO, Ben! You know better than that. 🙂 Don't set current.anything in an async or after if you can help it.



Business Rules Best Practices - ServiceNow Wiki



There's no current.update() after/async so people put one in, that triggers the business rules again (which causes business rules to run again.) See the issue here?



If you want the next number, use it as a default value in the dictionary. See task.number as an example.