Advanced Condition for Notification

tom_pritchard
Kilo Contributor

Hello,

 

Our helpdesk has requested a notification be built to notify them when the customer visible notes field changes. A recent addition to the request is that the notification trigger only when the Caller updates the customer visible notes. The notification worked until I added the advanced condition. The script currently looks like this:

 

if (current.sys_updated_by == current.caller_id ) {

true;

}

 

Again, that doesn't appear to be correct because the notification isn't sending. Is something incorrect with the script?

 

Thanks!

1 ACCEPTED SOLUTION

What version are you running on?   The reason I ask is John E. Jasinski has a point about using the "Send when" = "Record inserted or updated" option and the condition fields.   Makes it easy, and in this case, you should be able to use it, BUT, depends on the version you are running.   The "Send when" option was added in Berlin (I think).   Plus, in order to use the field comparison feature that you will need, you need to be running at least Calgary.



So, if you are, there is an existing OOC notification called "Incident commented" you could use as a starting point or modify.   There's actually 2 of them, one that goes out to the Assigned to and Watchlist users and the other to the Caller.   Choose the right one, and you can modify the Conditions field by adding the highlighted part below:



Incident_commented.png



Now, with all that being said, sometimes you do actually have to use some scripting.   And it is considered "existing functionality".   Not doing anything wrong - there's a script field there for us to use in these cases.   So if you must use a script, this should work for you:



if (current.sys_updated_by == current.caller_id.user_name ) {


        answer = true;


}



Like Tony Fugere, William Sun and Subhajit Das mentioned above, you need to return "true" or set "answer = true" in the script.   And remember, both the "Conditions" and "Advanced conditions" fields must return "true" for the notification to go out.   And, if you are testing yourself with your own tickets, the "Send to event creator" field would have to the selected for the email to go out (on the "Who will receive" tab or section, advanced view of the form).



OK, I'm done  


View solution in original post

11 REPLIES 11

tony_fugere
Mega Guru

Per the wiki (see section 2.2.1) http://wiki.servicenow.com/index.php?title=Email_Notifications#Creating_Email_Notifications



You need to set the global variable answer = true; on line 3 in order to complete this condition. This is common across the ServiceNow platform for script based condition fields like this. You'll see it on Workflow activities, Access Controls among others.



Let me know if that did not help.


Subhajit1
Giga Guru

Hi Tom,


Use this:-


if (current.sys_updated_by == current.caller_id && current.comments.changes()) {


true;


}



Thanks,


Subhajit


williamsun
Mega Guru

sys_updated_by is actually an open text field that is populated with the User ID (user_name) of the person who updated it.


maybe this might do the trick:


if (current.sys_updated_by == current.caller_id.user_name ) {


true;


}


William makes a good point here, I didn't pay attention to the rest of the code as the answer portion is what jumped out to me.



Subhajit's idea is also an interesting thought to make sure it only fires if the comments change, but you'll need's William's gem, too.



Go community input!