Business rule on cmdb_ci table

abdoulaye1
Kilo Explorer

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);

1 ACCEPTED SOLUTION

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


View solution in original post

10 REPLIES 10

abdoulaye1
Kilo Explorer

Below is the final version of the "After" business rule. I am getting "Undefined" on the stock variable even though when creating an asset I use a stockroom ( HQ, Tokyo, etc .,, )



var sn = current.getDisplayValue('serial_number');



var stock = "";
var pref;


var loc = new GlideRecord ("alm_asset");


loc.addQuery("serial_number",sn);
loc.query();
if (loc.next() )
{
gs.addInfoMessage("YES");
    stock = loc.stockroom.getDisplayValue();
 
}
//gs.addInfoMessage("Stock " + stock);



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;
  //gs.addInfoMessage ( "hostname " + "PANM" + sn);
}
else if ( current.manufacturer.getDisplayValue() == "Dell" )
{
current.name = pref + "WIN" + sn;
   
}
current.update();
gs.addInfoMessage(sn + "---" + current.manufacturer.getDisplayValue() + "---" + stock + " " + pref);


Hi Abdoulaye,



Can you try to log if even it is finding the record or not i.e getRowCount(). Also try to give the highest order number for the business rule.


Hi Pradeep,



Thanks for your reply. The row count is still 0 after I've set business rule order to the highest number


Okay.Does it update if you manually later go and update the cmdb_ci record. Please confirm. Just wanted to be sure our query works correctly.