Email notification should not triggered when the incident record is created with the state of closed

DeepikaR1661877
Tera Contributor

Hi every one,

I have one issues, when the incident record is created with the state of closed then the email notification should not triggered, but it's should trigger when the state is changed to one state to other.so i have created the event registry added into this BR and trigger this into the notification, how can i add the condition

1.when the SIR Created with the state of closed then notification should not trigger

2.When the SIR Created the Draft state then the state is changes from one state to closed the notification should be triggered,

BR condition,

(function executeRule(current, previous /*null when async*/) {
 
if (current.assignment_group.changes()) {
        gs.eventQueue('event name', '', '');
    }
 
 
})(current, previous);
6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@DeepikaR1661877 

why not update the BR condition appropriately?

BR is on which table and share configuration screenshots of that BR

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

@DeepikaR1661877 

you can separate out the event trigger logic in 2 different BR

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

AAGAMB
Tera Contributor

Hi Deepika,

Personally, I feel that a Flow Designer approach might be better for implementing the above situation, as it provides a more intuitive and maintainable way to handle such conditions. However, if you're sticking with a Business Rule, you can try modifying the script as follows:

(function executeRule(current, previous /*null when async*/) {
    // Check if the state is 'Closed' when the record is created
    if (current.isNewRecord() && current.state == 'Closed') {
        return; // Exit without triggering the event
    }

    // Check if the state has changed from any value to 'Closed'
    if (!current.isNewRecord() && current.state.changesTo('Closed')) {
        gs.eventQueue('sir.state.changed.to.closed', current, current.assigned_to, current.assignment_group);
    }
})(current, previous);

 

I have tried the above one it's not working, email not triggered all the scenario.