
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2018 11:08 AM
Hi community.
This is my first community post here, so please bear with me 🙂
I have been trying to change the Business Rule on Calculate Display Name for alm_asset. The current value (default) is: current.asset_tag.changes() || current.model.changes() || current.operation() == 'insert'
Basically, what I am trying to change is that the display name is calculated not from an asset tag but from a serial number. Question is: wouldn't it be logical to just change asset_tag to serial_number and it should work?
Here's the screenshot on what I have now (Kingston):
So, how do you go about changing asset_tag to serial_number that works? What are the steps I need to take to make this happen? I have been mind-boggled for two days now and nothing I try is working.
I would like to change the behavior for current assets and any new assets that get loaded either via load data or manually.
Please help.
Thank you in advance.
Solved! Go to Solution.
- Labels:
-
Enterprise Asset Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 03:32 AM
There are different views on this but I personally don't really like to alter ootb business rules but rather create copies of them and then deactive the ootb rule when the new one works.
As for what you are trying to do you wouldn't actually look in the busines rule itself to change it from using serial number instead of asset tag since it's using a AssetUtils which is a Script Include (see below). The only thing you would accomplish by changing asset_tag so serial_number in the condition-field is just change so that it triggers when serial_number is change and not asset_tag. In order to change the value you would either have to change the code in the script include or just create a new BR which accomplishes the same thing without changing an OOTB script include. The negative part to not use the script include is that if that function is used in some other business rule, script etc then you would get the asset_tag again and not the serial_number.
Anyway the code need to set the display name to serial_number + model should be the code snippet below. Now this doesn't take into account if the serial_number of model is missing so if both were missing you would just get a display name like " - " but a check like that can easily be added. You have one in the script include for example
current.display_name = current.serial_number + " - " + current.model.display_name;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 04:15 AM
You could use a fix script like below. Basicaly just loop through all the records in alm_asset and do the same thing that you do in the business rule. I've just added the counter since I didn't want it to loop through all assets when testing and I wanted to print out the sys_id just to keep track.
var asset = new GlideRecord('alm_asset');
var intcounter = 0;
asset.query();
while(asset.next() && intcounter < 10) {
gs.print(asset.sys_id);
asset.display_name = asset.serial_number + " - " + asset.model.display_name;
asset.update();
intcounter = intcounter +1;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 04:42 AM
Hi Simon.
This is fantastic, you really helped me through here, much appreciated.
Your script contains the counter for 10 records, so if I just remove this piece of code, it should run through?
var asset = new GlideRecord('alm_asset');
var intcounter = 0;
asset.query();
gs.print(asset.sys_id);
asset.display_name = asset.serial_number + " - " + asset.model.display_name;
asset.update();
intcounter = intcounter +1;
}
Thanks again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 05:01 AM
Glad to help, and exactly, just remove the counter once you've tested it on 10 records. You can also remove the gs.print line since you will runt it in the background anyways.
/Simon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 07:22 AM
Thanks!