The CreatorCon Call for Content is officially open! Get started here.

Need Business Rule condition to check related list

Maria DeLaCruz
Tera Guru

Hello,

On our change form, we've added a related list by creating a new "Relationship" called "User Notification".   This shows any user notification(s) created that is associated with the current change record.   The user notification is a catalog item.  


I created the following Business Rule to redirect user to the notification form from the change record (if "User Impact" is selected).   I need a condition to check if there's already an existing user notification associated with the change record.   If there is an existing user notification, I do not want to run the business rule.   Not quite sure what condition to put.   Any help would be appreciated.

Thanks,
Maria

1.jpg

3 REPLIES 3

ohhgr
Kilo Sage

Hi Maria,



How are you maintaining the relationship between the change record and the requested item? I mean from which table you pull the data to show in the related list and using which conditions?



I think same can be used in the business rule to avoid duplication.



Thanks


Mandar


giora_tamir
ServiceNow Employee
ServiceNow Employee

Echoing Mandar Vedak, where do you store the notifications so a check can be made? In theory, a complex condition can be implemented inside the business rule body with no significant loss of performance. The business rule is equivalent to


if (condition) then {


    business-rule-body


}



So it is fine to put part of the condition at the top of the body. The downside is that this kind of format will look wrong during debugging as it will show the BR being run even though the BR body is then ignored due to the complex condition.


Sachin Jain1
Giga Contributor

Hello Maria,



For your case condition can't be put in condition field beause you are running the business rule on change table and checking the record on related list. the condition needs to be put in script body.You need to first fetch record from related table for current change record using GlideRecord and if record found than you need to check condition eg:



var parentChange = current.sys_id; //sysId of current change


var gr = new GlideRecord('Your_Notification_table');


gr.addQuery('Relative_field_between_notification_and_change', parentChange);


gr.query();


if(!gr.hasNext())       //if there is no record in related list for current change


{


//You Business rule code statements


}




Regards,


Sachin