Prevent duplicate asset tags and serial numbers

stephaniet
Kilo Expert

Is there a way to prevent duplicate asset tags and serial numbers in the Asset Management module?

1 ACCEPTED SOLUTION

The following business rule will throw an error message "Serial number or asset tag already exists" to the user if tries to insert duplicate serial number or asset tag and stops the insert. I have tested this and it should work for you. Make sure you only run this Business rule before insert only.



var grDupCheck = new GlideRecord('alm_asset');


  grDupCheck.addQuery('serial_number', current.serial_number).addOrCondition('asset_tag',current.asset_tag);


  grDupCheck.query();


  if (grDupCheck.next()) {


  gs.addErrorMessage("Serial number or asset tag already exists");


  current.setAbortAction(true);


  }


View solution in original post

15 REPLIES 15

Oops I put in a client side message by mistake. This is what will show the message on the Server side since this is a business rule.



gs.addInfoMessage("Hello World");



Scripting Alert, Info, and Error Messages - ServiceNow Wiki




g_form is client side and gs is server-side.



http://wiki.servicenow.com/index.php?title=Differences_Among_Scripts#gsc.tab=0



The following business rule will throw an error message "Serial number or asset tag already exists" to the user if tries to insert duplicate serial number or asset tag and stops the insert. I have tested this and it should work for you. Make sure you only run this Business rule before insert only.



var grDupCheck = new GlideRecord('alm_asset');


  grDupCheck.addQuery('serial_number', current.serial_number).addOrCondition('asset_tag',current.asset_tag);


  grDupCheck.query();


  if (grDupCheck.next()) {


  gs.addErrorMessage("Serial number or asset tag already exists");


  current.setAbortAction(true);


  }


Is there any way to not have this apply to an extended table?   The extended table is an inspections table, where one asset can have multiple inspections.   But since we pull up the asset number, it kicks back the message that the asset or serial number already exist, if that same asset has already had one inspection done before.


Stephanie,



    What do you mean an asset had inspection done? Are you changing any values on the asset table while doing a inspection? Are you running this Business rule only before insert but not update?


Hi Abhinay Erra, 

 

if we want to make the business rule work for update , how can we achieve that, as the user can update the existing record also. 

In addition to it, I have observed that before business rule on insert and update restricts the creation of asset but creates the CI due to the OOB business rule "Create CI on insert" , that evalutates to true.

 

please help!