- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 11:48 AM
Hoping someone can lend a little logic to my situation.
I'm currently defining an SLA which will run on the RITM table. At the SLA milestones I'd like to send notifications to those who have an active SCTASK associated with that particular RITM, assigned to them. The problem that I'm running into is when one user has multiple SCTASK records assigned to them. So let's say for an onboard, one user may have 3 tasks while another has 2. I'd like to NOT send that one user a notification for each record and instead only send them one. My notification email script actually queries and prints a list of all active tasks related to the RITM, along with who they're assigned to. So each user only needs one notification regardless of if they have 3 SCTASK records assigned to them.
I've included my current Run Script and my Notification Script. I believe what I need to do is query for each active record on the Run Script, but only trigger an event once for each user. I just haven't been able to figure out how to do that nor do I know if it would be the best way to do it. Any help would be greatly appreciated!
Workflow Run Script:
var notify = new GlideRecord('sc_task');
notify.addQuery('request_item', current.task.sys_id);
notify.addQuery('active', true);
notify.query();
while(notify.next()){
gs.eventQueue('sla.warning.50',current,current.task.sys_id,notify.assigned_to);
}
Notification Email Script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var rrecord = new GlideRecord('sc_task'); //create new query object on the catalog task table.
rrecord.addQuery('request_item', event.parm1); // query the catalog task table for all tasks associated with the request item's sys_id sent over through parm 1.
rrecord.addQuery('active', true); // query the catalog tasks table only for active tasks.
rrecord.query(); // run query
while(rrecord.next()){
var sctaskLink = rrecord.getLink(); //get the link to the sc_task record.
template.print('Catalog task: ' + '<a href="' + sctaskLink + '">' +rrecord.number +'</a>' + '<br>' ); //print the link
template.print('Short description: ' + rrecord.short_description + '<br>'); //print the short description
template.print('Assignment group: ' + rrecord.assignment_group.getDisplayValue() + '<br>'); //print the assignment group value
template.print('Assigned to: ' + rrecord.assigned_to.getDisplayValue() + '<br><br><br>'); //print the assigned to value
}
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2019 01:07 PM
Thank you for your help. I've figured this out. I needed to use ArrayUtil with the ".unique" method to parse out the unique values. Then I sent them through Event parm 2 as a comma separated value. On my email notification I have the "recipients in Event parm 2" box checked. So even though there are multiple records assigned to each user, it only generates one event and sends each user through parameter 2, one time. I query and print the all the associated records in my notification script.
var array1 = [];
var notify = new GlideRecord('sc_task');
notify.addQuery('request_item', current.task.sys_id);
notify.addActiveQuery();
notify.query();
while(notify.next()){
array1.push(notify.assigned_to + '');
}
var arrayUtil = new ArrayUtil();
gs.eventQueue('sla.warning.50',current,current.task.sys_id,arrayUtil.unique(array1));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2019 01:07 PM
Thank you for your help. I've figured this out. I needed to use ArrayUtil with the ".unique" method to parse out the unique values. Then I sent them through Event parm 2 as a comma separated value. On my email notification I have the "recipients in Event parm 2" box checked. So even though there are multiple records assigned to each user, it only generates one event and sends each user through parameter 2, one time. I query and print the all the associated records in my notification script.
var array1 = [];
var notify = new GlideRecord('sc_task');
notify.addQuery('request_item', current.task.sys_id);
notify.addActiveQuery();
notify.query();
while(notify.next()){
array1.push(notify.assigned_to + '');
}
var arrayUtil = new ArrayUtil();
gs.eventQueue('sla.warning.50',current,current.task.sys_id,arrayUtil.unique(array1));