Issue with before Business Rule If condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 02:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 02:27 AM
No luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 02:39 AM
Hello @MohanambalN ,
The Model Category is the 'Reference' typed field. So the 'current.getValue('model_category')' will return with the SysID of the model category.
So rather than this, use the 'current.getDisplayValue('model_category')' to get the Display value of the Model Category. And in the if condition use the Single or Double quotes like below :
if (modelCategory == 'communicationDevice')
Use the below full code:
(function executeRule(current, previous /*null when async*/)
{
var communicationDevice = gs.getProperty("itsm.asset.model_category.communication_device.sys_id");
var modelCategory = current.getDisplayValue('model_category'); //(Display Value of the Model Category)
gs.log("Model Category :"+modelCategory);
gs.log("Model Cqategory1 :"+communicationDevice);
if (modelCategory == 'communicationDevice') //Use the exact Display name of the Model category
{
current.setValue('u_device_name', current.u_imei_number);
}
else
{
current.setValue('u_device_name', current.serial_number);
}
})(current, previous);
Let me know if you have any further questions or issues.
And if the above solution resolve your issue, Please mark the solution as 'Accepted Solution' also mark it as Helpful.
Thank You.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 03:01 AM
First: with 'setValue' you also need an .update(); or is this just a part of the code?
Then: what do your logs say? Do you get the same sys_id returned? in your logs? Also: what is the reason for getting the sys_id through a property? Why not 'if(current.model_category = 'sys_id'){'
Also: it runs before insert/update, so with an insert you need to be sure the system already knows the model category.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 06:42 AM
As a best practice, I don't want to user any hard coded 'Sys_ID' in script. Hence, created the property and stored the Sys ID in property.
Noticed that if we directly use the 'sys_id' in script it is working as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 06:48 AM
Hi @MohanambalN Try below code
(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.log("Model Category from record: " + modelCategory);
gs.log("Communication Device Sys ID from property: " + communicationDeviceSysId);
if (modelCategory && communicationDeviceSysId && modelCategory.trim() === communicationDeviceSysId.trim()) {
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);