Email notification and additional comments.

Maxwell3
Kilo Guru

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.

1 ACCEPTED SOLUTION

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!

View solution in original post

12 REPLIES 12

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!

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,

Allen,

 Thank you,