- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 01:44 AM
When I create a new asset in "alm_hardware" table, a ci also get created in the "cmdb_ci table. I have create a before business rule on cmdb_ci table that will rename the ci name in the cmdb_ci table with serial number and also whatever the stockroom name was when creating the asset. My script is not getting the stockroom name because it looks like the ci get created first before the asset get created. Any idea how can I capture the stockroom name correctly?
Here is my business rule
var sn = current.getDisplayValue('serial_number');
var stock = "";
var pref;
var loc = new GlideRecord ("alm_hardware");
loc.addQuery(sn);
loc.query();
if ( loc.next() )
{
stock = loc.stockroom.name;
}
if ( stock == "HQ" )
{
$pref = "SJC";
}
else if ( stock == "Amsterdam" )
{
$pref = "AMS";
}
else if ( stock == "Plano" )
{
$pref = "DFW";
}
else if ( stock == "Singapore" )
{
$pref = "SIN";
}
else if ( stock == "Tokyo" )
{
$pref = "NRT";
}
if ( current.manufacturer.getDisplayValue() == "Apple" )
{
//current.ci.setDisplayValue(sn);
var leight = sn.substr(sn.length - 8);
current.name = $pref + "MAC" + leight;
}
else if ( current.manufacturer.getDisplayValue() == "Dell" )
{
current.name = pref + "WIN" + sn;
}
//gs.addInfoMessage(sn + "---" + current.manufacturer.getDisplayValue() + "---" + stock);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 06:26 PM
For reference field you can restrict it with the help of reference qualifier. Please refer the sample example 4.3.2.2 in the below wiki link.
http://wiki.servicenow.com/index.php?title=Reference_Qualifiers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 05:50 PM
Yes it does manually update.
The business rule update the ci name in the cmdb_ci as well to
undefinedWIN12345 if ( 12345 is the serial number )
It doesn't seem to get the stockroom.
There is a out of box business rule that create a CI record when you add a new asset and it will create the ci with the model name. Maybe I need to find that business rule and modify that instead ( if I can find it ) instead trying a After business rule on Insert.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 06:03 PM
Yes correct.
So while creating the record it self you can update the ci name. You can search for script contains cmdb_ci. In that way you will be able to figure out the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 06:18 PM
Thanks. So there is no way to get the stockroom name with a after business rule the way I am trying to do it. You will figure the data has been record to the database, therefore I should be able to pick up the stockroom name.
Another question for you if I might.
When creating the asset, I will have to
populate the Vendor field ( reference fields ) only have 2 values to choose from, Apple and Dell
also populate Model field ( reference fields ) have many value like "Apple MacBook air, Apple MacBook pro, Dell Latitude, Dell E7500, etc .. )
is there a way when you pick Apple as Vendor, to adjust the model to only show Apple models.?
Maybe I should create a new threat for this.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 06:20 PM
No problem. Here you go.
Please mark the response as correct/helpful if this answers your questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 06:24 PM
Thanks. That is using choice list. My case is 2 reference fields