The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Trigger event from business rule

LJ_23
Tera Contributor

Hi team,  I have a business rule set up to fire an event on an email notification. I can see in the event log that the event is being triggered, however it is not sending the email notification for some reason!

 

Business rule & BR script:

Table: x_lbg_fbs_case_fbs_case

When: After , Insert, Update

Filter Conditions: none

 

Script:

(function executeRule(current, previous /*null when async*/) {
    // Check if the assigned_to field is updated and not empty
    if (current.assigned_to.changes() && current.assigned_to) {
        // Call the event
        gs.eventQueue('x_lbg_fbs_case.LBGGFScasenew', current, current.assigned_to, previous.assigned_to);
    }
})(current, previous);
 
On the email notification:
Table: x_lbg_fbs_case_fbs_case
Triggered by event: x_lbg_fbs_case.LBGGFScasenew
Who will receive: Assigned to 
6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@LJ_23 

Ensure "Event parm1 contains recipient" as True in notification

Remove this -> Who will receive: Assigned to 

Send to Event Creator - True

update as this

gs.eventQueue('x_lbg_fbs_case.LBGGFScasenew', current, current.assigned_to.email.toString(), previous.assigned_to);

Also ensure that user is active, not locked out, has email and has notification preference enabled.

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

Hi I enabled the user to receive email notifications in dev, assuming they will have access to receive in prod.

This has solved the issue and the email notifications are being triggered, but I need to include 5 assignment groups into the business rule script. I have created a system property 'GFS.case.email.notification' - how can I implement this property into my existing business rule script so that when the email notification triggers it only is assigned to the 5 groups (I have included all 5 sys id's inside the value within the system property)

Hi @LJ_23 

You can add below logic in your script.

var assg= gs.getProperty('GFS.case.email.notification'); //get the value from property

//replace current.assignment_group.toString() as per your requirement
if(assg.indexOf(current.assignment_group.toString()) > -1) // check if current assignment group is part of the list
{

//your logic here.
gs.eventQueue('x_lbg_fbs_case.LBGGFScasenew', current, current.assigned_to.email.toString(), previous.assigned_to);

}

 

You can remove below line from your existing code and add as a condition in your BR. 

if (current.assigned_to.changes() && current.assigned_to) 

Filter Conditions - 

Assigned To || changes AND Assigned To || is Not empty

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Am i adding this script to the existing script, I have deleted the script in the business rule and added both this new script and the condition but now it doesnt work at all and no email is being triggered.