How to add a condition from another table for email notifications

NFGDom
Mega Sage

Hello!

Under System Notification -> Email -> Notifications I'm looking at the OOTB Incident Resolved notification.

find_real_file.png

And its default condition is to send when Incident State changes to Resolved.

find_real_file.png

I'd like to add an and condition that checks to see if the incident has any Requests (sc_request) related to it. If it has a request, do not send notification. If it does not have a request, send the notification.

From what I can tell, when I click create request within the incident in the hamburger menu, it sets the incident as parent on the request. Not on the incident.

I unfortunately do not know at this time how to make an advance condition with scripting. Also when showing related fields, I did not see anything related to the request table.

Any help would be appreciated!

Thanks!
Dom

1 ACCEPTED SOLUTION

Strange, well some other OOB ones don't include the answer variable you could try this instead:

var g = new GlideRecord('sc_request'); 
g.addQuery('parent', current.sys_id); 
g.query();
if(g.hasNext()) {
   false;
} else {
	true;
}

View solution in original post

8 REPLIES 8

Elijah Aromola
Mega Sage

Try something like: 

var flag = true; 
var g = new GlideRecord('sc_request'); 
g.addQuery('parent', current.sys_id); 
g.query();
if(g.hasNext()) {
   flag = false; 
}

return flag; 

Please mark this as helpful/correct if it answered your question!

Elijah's script will work but not knowing additional details like if you do want to send the notification IF the request is closed then you can add additional logic to the query:

var flag = true; 
var g = new GlideRecord('sc_request'); 
g.addQuery('parent', current.sys_id); 
g.addQuery('active', true);
g.query();
if(g.hasNext()) {
   flag = false; 
}

return flag; 

NFGDom
Mega Sage

Thank you both for the response. When I paste the code into the advanced condition form I receive a parsing error.

find_real_file.png

 

@Michael Ritchie We don't care about the state of the request in this case. We have a separate notification for that.

I just looked at other out of the box notifications that have advanced scripts and they are all using the "answer" variable.  Use this script instead:

answer = true; 
var g = new GlideRecord('sc_request'); 
g.addQuery('parent', current.sys_id); 
g.query();
if(g.hasNext()) {
   answer = false; 
}