- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 11:53 AM
Is there a way to prevent duplicate asset tags and serial numbers in the Asset Management module?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2016 06:13 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2016 06:06 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2016 06:13 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2016 10:05 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2016 10:12 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 06:27 AM
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!