- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2020 09:01 AM
Hi,
someone help on incident script,
send incident details list to assigned to if incident state is OnHold on single notification .
ex: DavidLoo hasbeen assigned to 10-incidents , in 10-incidents there are 7 incidents have state -onhold. so DavidLoo should receive 7-incident details (number, shortdescription, caller , priority) in a single email.
i tried with below script, it is getting single incident details, how to get all in single email.
template.print("number :"+"${number}\n");
template.print("number :"+"${priority}\n");
template.print("number :"+"${caler_id}\n");
template.print("number :"+"${short_description}\n");
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 10:00 AM
Hi,
I just updated the job code
It triggered 3 emails to 3 different users
Email triggered to David Loo has incident info Assigned to David Loo
Email triggered to Rosie Mathews has incident info Assigned to Rosie Mathews
Email triggered to Fred Luddy has incident info Assigned to Fred Luddy
Now the only thing you need to check is why it didn't send email to other 6 users
Updated Job Code:
sendEmail();
function sendEmail() {
var gr = new GlideAggregate("incident");
gr.addAggregate("COUNT");
gr.addEncodedQuery('active=true^assigned_toISNOTEMPTY');
gr.groupBy("assigned_to");
gr.query();
while(gr.next()) {
var user = gr.assigned_to;
var incRec = new GlideRecord('incident');
incRec.get('assigned_to', user);
gs.eventQueue('test_list', incRec, incRec.assigned_to, incRec.assigned_to);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 06:48 AM
https://dev86634.service-now.com/
ankur.bawiskar / 123456
scheduled-job : Test- List
Notification : Test- List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 08:54 AM
Small change in job; we need to use the uniqueArray for length
Also we need to send the assigned_to user so that it will help in our email script query
Job script change:
sendEmail();
function sendEmail() {
var arr = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^assigned_toISNOTEMPTY');
gr.query();
while (gr.next()) {
arr.push(gr.assigned_to.toString());
}
var arrayUtil = new ArrayUtil();
var uniqueArray = arrayUtil.unique(arr);
var inc = new GlideRecord('incident');
inc.addQuery('assigned_to', 'IN', uniqueArray);
inc.setLimit(uniqueArray.length);
inc.query();
while (inc.next()) {
gs.eventQueue('test_list', inc, gs.getUserID(), inc.assigned_to);
}
}
Small change in email script:
template.print("<table width=70% border=1><tr bgcolor=#e2e0de><td>Number</td><td>Priority</td><td>Caller ID</td><td>Short Desc</td></tr>");
var inc = new GlideRecord('incident');
inc.addQuery('active', true);
inc.addQuery('assigned_to', event.parm2);
//inc.addQuery('state','5');
inc.query();
while (inc.next()) {
template.print("<tr><td>" + inc.number + "</td><td>" + inc.priority + "</td><td>" + inc.caller_id.getDisplayValue() + "</td><td>" + inc.short_description + "</td></tr>");
}
template.print('</table>');
It worked as below:
Total Incidents with Active=true && Assigned to Not EMPTY = 27
Unique Assigned To users = 9
So email triggered 9 times
Preview of Email:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 09:00 AM
let me check and i will update you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 09:26 AM
Sure
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 02:05 AM
Hope you are doing good.
Did you got a chance to check on the solution provided to resolve your query?
If your query is resolved please mark my answer as correct & helpful and close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader