How to set an Condition in the notification (sys_notification)

DNC
Tera Contributor

Hi All,

We have a notification that is being generated and displayed in the agent workspace.

The filter condition is set to "State Changes," and the notification is being triggered for all state changes.

However, our requirement is that the notification should not be generated when the state changes from Resolved to Closed.

 

Help me,

 

Thanks

Nagarjuna

4 REPLIES 4

Juhi Poddar
Kilo Patron

Hello @DNC 

 

This can be achieved by adding the code in advanced condition in the notification.

 

// Check if the notification should be sent
(current.state.changes() && !(current.state == 'Closed' && current.state.changesFrom('Resolved')));

 

Refer the screenshots of notification configuration:

JuhiPoddar_0-1730980060466.png

  • If advanced condition field is not visible, configure the form layout.
  • This will trigger the notification whenever the state changes except when the state changes from Resolved to Closed.

This solution is tested in my PDI and it works.

 

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thank You

Juhi Poddar

 

 

 

Bhavya11
Kilo Patron

Hi @DNC ,

 

you can try below way to achieve this 

1 create an event by following this steps

  in navigation type event then click on Registry

   

Bhavya11_0-1730980229170.png

then click on new fill name and table

Bhavya11_1-1730980257579.png

 

then goto notification update the when to run section like below

Bhavya11_2-1730980287462.png

 

who will receive like this 

Bhavya11_3-1730980315885.png

then goto Business rule create After update business rule

Bhavya11_4-1730980364168.png

 

script 

Bhavya11_5-1730980375045.png

 

 

(function executeRule(current, previous /*null when async*/) {

	if (current.state == '7' && previous.state == '6') { // 7 is closed and 6 is Resolved 
    // If the state is changing from Resolved to Closed, do not send the notification
    return;
}else{
	gs.eventQueue("state.changes",current,current.caller_id);
}

})(current, previous);

 

 

it will not trigger the notification if state changes from Resolved to Closed.

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

 

Runjay Patel
Giga Sage

Hi @DNC ,

 

Simple use below condition, i have tested it, its working.

RunjayPatel_0-1730980536833.png

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

DNC
Tera Contributor

@Runa Yes, It is working, But our requirement is if the Incident is moving from Resolved to Closed only, we need to stop that notification.

 

But, our changes are stopping the notification if the incident is moving from WIP, On Hold to Closed.