Issue with before Business Rule If condition

MohanambalN
Tera Contributor
In alm_asset table I have created the below Business Rule(OnBefore) which runs on insert and update.
 
But it always going to else part and updating Serial number in the Device Name.
If it is communication Device, then it should update the IMEI number as device name. 
 
(function executeRule(current, previous /*null when async*/)
{
   
var communicationDevice = gs.getProperty("itsm.asset.model_category.communication_device.sys_id");
var modelCategory = current.getValue('model_category');  //(category sys ID)
 

 

gs.log("Model Category :"+modelCategory);
gs.log("Model Cqategory1 :"+communicationDevice);

 

if (modelCategory == communicationDevice)
{
    current.setValue('u_device_name', current.u_imei_number);
}
else
{
    current.setValue('u_device_name', current.serial_number);
}

 

})(current, previous);
 
Please someone help me to fix the issue.
 
Thanks
11 REPLIES 11

MohanambalN
Tera Contributor

Hi,

 

Thanks for your response. But the above code also not working.

 

Regards,

Mohanambal

@MohanambalN 

are you sure you are doing the correct comparison?

(function executeRule(current, previous /*null when async*/) {
    var communicationDeviceSysId = gs.getProperty("itsm.asset.model_category.communication_device.sys_id");
    var modelCategory = current.getValue('model_category'); 
    gs.info("Model Category from record: " + modelCategory);
    gs.info("Communication Device Sys ID from property: " + communicationDeviceSysId);
    if (modelCategory && communicationDeviceSysId && modelCategory.toString() == communicationDeviceSysId.toString()) {
        gs.log("Updating device name with IMEI number.");
        current.setValue('u_device_name', current.u_imei_number);
    } else {
        gs.log("Updating device name with Serial number.");
        current.setValue('u_device_name', current.serial_number);
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader