Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Email notification advanced condition script to be combined

nmcl
Giga Expert

I have the below code in an advanced condition of an email notification. However, I need to join the queries together so that if both are true it sends.

If I have either/or on it's own it works, but I cannot work out how to join them. I have tried the usual && between statements.

//the below works on it's own

if (current.variables.u_disable_opening_notification == "No"){

answer = true;

}

//the below works on it's own

if (sc_request.requested_for != current.u_requested_for){

answer = true;

}

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I would probably compare to the opened_by field rather than the requested for from the request, but you could do either.   You just need to reference the current object, so current.request.requested_for there. Try this:



if (current.variables.u_disable_opening_notification == "No" && current.request.requested_for != current.u_requested_for){


  answer = true;


}


View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Nat,



Is this the whole script? In your second if statement what is sc_request.requested_for referring to? Did you declare sc_request somewhere earlier? If not that condition should be current.sc_request.requested_for != current.u_requested_for



The following should work:


if (current.variables.u_disable_opening_notification == "No" && current.sc_request.requested_for != current.u_requested_for){


    answer = true;


}


This is an on Insert notification on the sc_req_item table. This is the whole script.



The intention is...



1 - Checks that in the variables of the item the disable notification option is set to No


2 - Checks against the parent REQ of the current RITM to compare the 'requested_for', so only sends if different.



Scenario 1


- Ticket logged by me on Dan's behalf


sc_request.requested_for       would be myself


current.u_requested_for           would be Dan




In this example I would expect it to send (Dan would get this, I would get the separate REQ opening notification)



Scenario 2


- Ticket logged by me for me


sc_request.requested_for       would be myself


current.u_requested_for           would be myself



In this example I would expect it to not send (as I would get the separate REQ opening notification)


Brad Tilton
ServiceNow Employee
ServiceNow Employee

I would probably compare to the opened_by field rather than the requested for from the request, but you could do either.   You just need to reference the current object, so current.request.requested_for there. Try this:



if (current.variables.u_disable_opening_notification == "No" && current.request.requested_for != current.u_requested_for){


  answer = true;


}


Thanks Brad, it worked using...



if (current.variables.u_disable_opening_notification == "No" && sc_request.requested_for != current.u_requested_for){  


    answer = true;  


}