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

Abhinay Erra
Giga Sage

Write a Before Insert Business rule. Add this script into the business rule



var grDupCheck = new GlideRecord('alm_asset');


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


  grDupCheck.query();


  if (grDupCheck.next()) {


  current.setAbortAction(true);


  }


}


Thank you so much!


g_form methods are not available on server side. Since Business Rules are server side, you cannot use those methods, they are only available on client scripts


I tried adding the line as shown, but when I do that, it will still submit the record and not abort it.   I don't get a message either.