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

Hi Chuck, Thanks! Unfortunately I can't just set it as the default value because I have certain conditions when an asset tag will be created or not.



In other words, I need to have the system create an asset tag only if the system is not a virtual machine (is virtual == false).



Set Default Value AFTER record is created


Ah. I missed that you were looking for an asset number and not a regular ticket number.



If it's still not working, I recommend enabling business rule debugging. Go to System Diagnostics> Debug Business Rules (detailed) and make your update. Scroll down the page to see the debug output. You'll see when business rules were run (or skipped) and what values were used. This should help determine when/why things are triggered and where the skipped value is coming from.


OK I have enabled debugging but it all looks normal to me.... The GetAssetTag business rule only runs once and returns the value 30372. The one prior to this was 30370.






1:00:01.211: Execute before query business rules on sys_user_group:


11:00:01.211: ==> 'group query' on sys_user_group:


11:00:01.211: <== 'group query' on sys_user_group:


11:00:01.211: Finished executing before query business rules on sys_user_group:


11:00:01.227: Execute before insert business rules on cmdb_ci_computer:test before engines (order <1000)


11:00:01.228: ==> 'assign processor' on cmdb_ci_computer:test


11:00:01.229: <== 'assign processor' on cmdb_ci_computer:test


11:00:01.229: ==> 'GetAssetTag' on cmdb_ci_computer:test


11:00:01.235:                     asset_tag: => 30372


11:00:01.235: <== 'GetAssetTag' on cmdb_ci_computer:test


11:00:01.236: === Skipping 'Null out asset on insert and stay' on cmdb_ci_computer:test; condition not satisfied: Condition: !current.asset.ci.nil()


11:00:01.236: === Skipping 'SNC CMDB Category' on cmdb_ci_computer:test; condition not satisfied: Condition: current.category.isNil()


11:00:01.236: === Skipping 'validateCfgAutoChangeWhenCloning' on cmdb_ci_computer:test; condition not satisfied: Filter Condition: cfg_auto_changeISNOTEMPTY^EQ


11:00:01.236: === Skipping 'Virtual Computer Check' on cmdb_ci_computer:test; condition not satisfied: Condition: current.serial_number.changes() || current.serial_number.hasValue() || current.correlation_id.changes() || current.correlation_id.hasValue()


11:00:01.237: === Skipping 'Computer Create CI validation' on cmdb_ci_computer:test; condition not satisfied: Filter Condition: u_input_manually=true^EQ


11:00:01.237: === Skipping 'Limit license metric combinations' on cmdb_ci_computer:test; condition not satisfied: Condition: current.metric_type && current.metric_type.split(GlideProperties.get('glide.ui.glide_list.separator', ',')).length > 1


11:00:01.237: === Skipping 'Populate CI Manufacturer' on cmdb_ci_computer:test; condition not satisfied: Condition: current.manufacturer.nil() && !current.manufacturer.changes() && (current.model_id.changes() || current.asset.changes())


11:00:01.238: Finished executing before insert business rules on cmdb_ci_computer:test before engines (order <1000)


11:00:01.238: Execute before insert business rules on cmdb_ci_computer:test after engines (order >=1000)


11:00:01.238: ==> 'Create Asset on insert' on cmdb_ci_computer:test


11:00:01.246: Execute before insert business rules on alm_hardware: before engines (order <1000)


11:00:01.246:       === Skipping 'Sanity check on pre-allocated' on alm_hardware:; condition not satisfied: Condition: current.substatus == 'pre_allocated'


11:00:01.248:       === Skipping 'Build bundle components on Insert' on alm_hardware:; condition not satisfied: Condition: current.sys_class_name != 'alm_consumable' && current.sys_class_name != 'alm_license' && current.model.bundle == true


11:00:01.248:       ==> 'Calculate display name' on alm_hardware:


11:00:01.248:                           display_name: => 30372 - Unknown


11:00:01.249:       <== 'Calculate display name' on alm_hardware:


11:00:01.249:       === Skipping 'Clear fields irrelevant for preallocated' on alm_hardware:; condition not satisfied: Condition: current.substatus.changes() && current.substatus == 'pre_allocated'


11:00:01.249:       === Skipping 'Create Stockroom Model Relation' on alm_hardware:; condition not satisfied: Condition: (current.stockroom.changes() || current.model.changes() || current.operation() == 'insert') && !current.stockroom.nil() && !current.model.nil()


11:00:01.251:       === Skipping 'Null out Ci on insert and stay' on alm_hardware:; condition not satisfied: Condition: (new AssetUtils().doesCiExist(current.ci)) && !current.ci.asset.nil()


11:00:01.254:       === Skipping 'Salvage value must be less than cost' on alm_hardware:; condition not satisfied: Condition: !isNaN(current.salvage_value) && !isNaN(current.cost) && (parseFloat(current.salvage_value) > parseFloat(current.cost))


11:00:01.254:       === Skipping 'Update location as needed' on alm_hardware:; condition not satisfied: Condition: (current.stockroom.changes() || current.assigned_to.changes()) && !current.location.changes()


11:00:01.255:       === Skipping 'Asset Retirement' on alm_hardware:; condition not satisfied: Condition: (current.install_status.changes() || current.operation() == 'insert') && current.install_status.equals("7")


11:00:01.255:       === Skipping 'Transition reserved to assigned' on alm_hardware:; condition not satisfied: Condition: current.install_status.changes() && current.install_status != 9 && current.install_status != 6 && current.install_status != 2 && !current.reserved_for.nil()


11:00:01.255:       === Skipping 'Inherit information from parent' on alm_hardware:; condition not satisfied: Condition: current.parent.changes() && !current.parent.nil() && current.parent.install_status != 0


11:00:01.255: Finished executing before insert business rules on alm_hardware: before engines (order <1000)


11:00:01.256: Execute before insert business rules on alm_hardware:30372 - Unknown after engines (order >=1000)


11:00:01.256:       === Skipping 'Create CI on insert' on alm_hardware:30372 - Unknown; condition not satisfied: Condition: current.sys_class_name != 'alm_consumable' && current.sys_class_name != 'alm_license' && current.ci.nil() && current.substatus != 'pre_allocated' && current.category.cmdb_ci_class != ''


11:00:01.256: Finished executing before insert business rules on alm_hardware:30372 - Unknown after engines (order >=1000)


11:00:01.276: Execute before insert business rules on fx_price: before engines (order <1000)


11:00:01.276:       ==> 'Convert to Reference Currency' on fx_price:


11:00:01.278:       <== 'Convert to Reference Currency' on fx_price:


11:00:01.278: Finished executing before insert business rules on fx_price: before engines (order <1000)


11:00:01.280: Execute after insert business rules on fx_price: after engines (order >=1000)


11:00:01.280:       ==> 'Generate prices' on fx_price:


11:00:01.283:       <== 'Generate prices' on fx_price:


11:00:01.283: Finished executing after insert business rules on fx_price: after engines (order >=1000)


11:00:01.294: Execute after insert business rules on alm_hardware:30372 - Unknown before engines (order <1000)


11:00:01.294:       ==> 'Create Expense Line' on alm_hardware:30372 - Unknown


11:00:01.297: Execute before insert business rules on fm_expense_line:EXP0069008 before engines (order <1000)


11:00:01.297:             ==> 'Set source allocation fields' on fm_expense_line:EXP0069008


11:00:01.305:                                 ci: => de0b2d4213931200a21a7b104244b0c4


11:00:01.305:                                 source_id: => 570ba54213931200a21a7b104244b0fe


11:00:01.305:                                 source_table: => alm_hardware


11:00:01.305:             <== 'Set source allocation fields' on fm_expense_line:EXP0069008


11:00:01.306:             === Skipping 'Source ID check' on fm_expense_line:EXP0069008; condition not satisfied: Condition: current.source_id.nil()


11:00:01.306:             ==> 'Move asset expense to configuration item' on fm_expense_line:EXP0069008


11:00:01.308:                                 source_id: 570ba54213931200a21a7b104244b0fe => de0b2d4213931200a21a7b104244b0c4


11:00:01.308:                                 source_table: alm_hardware => cmdb_ci


11:00:01.308:             <== 'Move asset expense to configuration item' on fm_expense_line:EXP0069008


11:00:01.308: Finished executing before insert business rules on fm_expense_line:EXP0069008 before engines (order <1000)


11:00:01.317: Execute after insert business rules on fm_expense_line:EXP0069008 before engines (order <1000)


11:00:01.317:             ==> 'Process CI Relationships' on fm_expense_line:EXP0069008


11:00:01.320: : Calling processCIParents for EXP0069008


11:00:01.320:             <== 'Process CI Relationships' on fm_expense_line:EXP0069008


11:00:01.321:             ==> 'Update Planned Task Actual Cost' on fm_expense_line:EXP0069008


11:00:01.321:             <== 'Update Planned Task Actual Cost' on fm_expense_line:EXP0069008


11:00:01.321:             ==> 'Process Top Task Parent' on fm_expense_line:EXP0069008


11:00:01.321:             <== 'Process Top Task Parent' on fm_expense_line:EXP0069008


11:00:01.321: Finished executing after insert business rules on fm_expense_line:EXP0069008 before engines (order <1000)


11:00:01.322:       <== 'Create Expense Line' on alm_hardware:30372 - Unknown


11:00:01.322: Finished executing after insert business rules on alm_hardware:30372 - Unknown before engines (order <1000)


11:00:01.322:                     asset: => 570ba54213931200a21a7b104244b0fe


11:00:01.322:                     model_id: => fb99bef04f2e96003a44b3318110c737


11:00:01.322: <== 'Create Asset on insert' on cmdb_ci_computer:test


11:00:01.322: Finished executing before insert business rules on cmdb_ci_computer:test after engines (order >=1000)


11:00:01.325: Execute after insert business rules on cmdb_ci_computer:test before engines (order <1000)


11:00:01.325: ==> 'Update model category' on cmdb_ci_computer:test


11:00:01.330: <== 'Update model category' on cmdb_ci_computer:test


11:00:01.330: Finished executing after insert business rules on cmdb_ci_computer:test before engines (order <1000)


11:00:01.439: >>> Preceding lines from previous transaction


Community Alums
Not applicable

You caught me, Chuck. I don't write enough BRs on a regular basis. I goofed.


kda617, do you have a condition on your BR so it only runs if the CI isn't virtual? I assume that is where you've put in that logic. This isn't going to specifically help with the skip problem, but it might.


Here is another interesting thought... Do you have something creating Asset tags on newly created Asset records, too? I don't think that it would use the same index, but perhaps something is happening twice here causing the skipped numbers...



Ben


Thanks again Ben, always stepping in to help! I actually goofed a little myself. The root cause of the issue was that there was another field on that table (a custom field created years ago by a previous administrator) that was also using the same numbering script. So I removed that field and it is working. Thanks all for the help.



Also, as a part of the solution I needed to set the property Assign a task number only upon insert (prevents unused numbers) to true



Thank you!