Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How do I script an email notification to send when specific users comment on a RITM?

xwharton
Tera Guru

Problem

I enabled a notification record to be triggered when comments are entered on a RITM.

All notifications are sent to the Service Desk assignment group; however, I want to help reduce the number of notifications that are sent by creating a script to do the following:

  • Only send email notifications when comments are entered/added by:
    • Event creator > Opened By field
    • The person listed on the Requested By field
    • Any person listed on the Watch List
  • And I DO NOT want any messages to be sent to the Service Desk if a comment is left by a fulfiller (person with an ITIL role)

Below are screenshots of what I have done so far. Thank you in advance for helping me with any scripting; this is not my strong suit. . . yet.

 

When to send

This is where I need the most assistance, particularly with the script based on what I want to achieve. 
XavierWharton1_0-1706928432261.png

 

Who will receive

XavierWharton1_1-1706928883797.png

 

 
5 REPLIES 5

Sid_Takali
Kilo Patron

Hi @xwharton  Write below script into Advanced Condition field 

 

 

 

if ((current.comments.changes()) && (current.sys_updated_by == current.opened_by || current.sys_updated_by == current.requested_by || current.sys_updated_by == watch_list)) {
    answer = true;
}

 

 

Refer below Screenshot 

SiddharamTakali_0-1707050450187.png

Please make my answer Correct/Helpful

Regards,

Siddharam

@Sid_Takali 

I tried the script that you suggested, and the result was that no emails were sent to the Service Desk assignment group. 
When I remove the code emails are sent, however, there is no filter for comments left by fulfillers.
I even tried modifying the script to include the following and encountered the same result:

if (current.comments.changes() && 
    (current.sys_updated_by == current.opened_by || 
     current.sys_updated_by == current.requested_by || 
     watch_list.includes(current.sys_updated_by))) {
    answer = true;
} else {
    answer = false;

I also tried the following combinations of the conditions plus the advanced conditions:

Combinations
Event Name: sc_req_item.commented.itil + Code referenced above as well as the code snippet that you provided to me

Event name: sc_req_item.commented + Code referenced above as well as the code snippet that you provided to me

 

xwharton
Tera Guru

Thank you @Sid_Takali I will test it out ASAP and mark as "Accept as Solution" once confirmed. 

By chance can you offer any tips on improving my scripting skills? There's so much that I want to do in the platform, but I get stuck on scripting. 

Hi @xwharton I would suggest you to complete the following "Scripting in ServiceNow Fundamentals" course from Now Learning. 

https://learning.servicenow.com/lxp/en?id=learning_course_prev&course_id=e728f68cdb5eff40de3cdb85ca9... 

 

Also try to complete lessons 1 – 14 of CodeCademy's JavaScript Fundamentals course.

 

And also try to learn from Chuck Tomasi 

https://www.youtube.com/watch?v=62Nabpb94Jw&list=PL3rNcyAiDYK2_87aRvXEmAyD8M9DARVGK 

 

I'm sure this will help you to write any script in ServiceNow.

Please make my answer Correct/Helpful

Regards,

Siddharam