- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2020 10:14 AM
Hello all,
Is there a way to trigger email notifications per the amount of Additional Comments?
So, if there is 1 additional comment the email notification would say Update 1 and if there is 2 Additional comments, the notification would say Update 2 and so on. These notifications will be triggered by the amount of additional comments in the current incident.
Right now, the notification is being triggered per update count but that is not efficient, the notification needs to be triggered per Additional comments count.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2020 05:22 PM
Hi,
Firstly, please mark any other reply of mine thus far as "Helpful", if it was.
Secondly, you could try something like this:
var setID;
var gr2 = new GlideRecord('sys_history_set');
gr2.addQuery('id', current.sys_id);
gr2.query();
if (gr2.next()) {
setID = gr2.sys_id;
}
var gr = new GlideRecord('sys_history_line');
gr.addQuery('set', setID);
gr.addQuery('field', 'comments');
gr.orderByDesc('sys_created_on');
gr.query();
if (gr.next()) {
template.print('gr.getDisplayValue('update'));
template.print('<br />');
}
So you have to grab the set for the history line "package". So you can get this by glide querying with the current.sys_id (so the current record this script is ran on), then we're tossing that over to a variable that we are going to use later in another glide query on the actual history line package, filtering those results for only records part of that set, then only comments, then only the latest comment, and then displaying that value update #.
However, if you're just trying to get the count of entries for "comments" then you can do: gr.getRowCount(); for example
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideRecord-getRowCount
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 06:37 PM
You're looping through with those while loops...
That's not what I gave you in my code.
I gave you if, not while.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2020 08:34 AM
Allen,
The 'if' statements did not work as intended, I had to use 'while' loops but neither one are working per my requirements. The code just prints out the same number repeatedly instead of iterating through in descending order.
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2020 11:28 AM
Allen,
Thank you,