How do I script an email notification to send when specific users comment on a RITM?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 06:55 PM
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.
|
Who will receive
|
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 02:58 AM - edited 02-04-2024 04:44 AM
Hi @Xavier_Wharton 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
Please make my answer Correct/Helpful
Regards,
Siddharam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 06:52 AM
@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 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 09:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024
09:17 AM
- last edited on
02-06-2025
05:59 AM
by
Steph Morillo
Hi @Xavier_Wharton I would suggest you to complete the following "Scripting in ServiceNow Fundamentals" course from Now Learning.
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