Business rule to trigger event for when case is opened and case is resolved, to send notifications

Daniel R2
Kilo Sage

Hi,

 

We are currently working with notifications, templates, etc. And working on when a case is commented it sends a notification, when a case is opened it sends a notification and when a case is resolved it sends a notificaiton.

To ensure we only have 1 notification and 1 template instead of 1 for each case types we are triggering by event on the notification.

 

So:

 

We have created 3 separate event registries, 3 separate notifications and 3 separate notification templates. 

 

1 for when a comment has been added to a case

1 for when a Case is Opened 

1 for when a Case is Resolved

 

We are now currently working on the business rule.

Please see screenshot for when a comment is added to a case.

DanielRyszka_0-1673861266078.png

 

Can anybody please provide support or guidance on the script that can be added in the advanced tab for when a case is opened or when a case is resolved.

3 REPLIES 3

Basheer
Mega Sage

Hi @Daniel R2 

You need to write through conditions

if(current.state.changesTo("open")){

//Trigger the event

}

else if(current.state.changesTo("Resolved")){

//Trigger the event

}

else if(){ //set the proper cnodition

//Trigger the event

}

else{

return false;}

 

Let me know if you need more help on this.

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Sagar Pagar
Tera Patron

Hi @Daniel R2,


Take a look at sample scripts and modify it accordingly-

 

if (current.operation() != 'insert' && current.comments.changes()) {
if (!isConnect())
gs.eventQueue("hr.case.commented", current, gs.getUserID(), gs.getUserName());
}

 

if (current.operation() == 'insert') {
gs.eventQueue("hr.case.opened", current, gs.getUserID(), gs.getUserName());
}

 

if (current.operation() == 'update'&& !current.cs_state == "6") // case state is resolved (6) {
gs.eventQueue("hr.case.updated", current, gs.getUserID(), gs.getUserName());
}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @Daniel R2 ,

Please check the below code and debug and modify according

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

// Add your code here
if(current.operation=="insert" && current.state=='open')
{
gs.eventQueue('incident.updated', current, gs.getUserID(), gs.getUserName()); // Expamle your event name and parameter
}
else if(current.operation=='update' && current.state=='resolved')
{
gs.eventQueue('incident.updated', current, gs.getUserID(), gs.getUserName()); // Expamle your event name and parameter
}
else if(current.opearation=='update' && current.comments.changes())
{
gs.eventQueue('incident.updated', current, gs.getUserID(), gs.getUserName()); // Expamle your event name and parameter
}
})(current, previous);

 

 

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.