Notifying group/assignee when RITM commented

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 06:18 AM
Good afternoon all
We have a number of catalogue items that generate change requests, and we would like to notify the assignment group/assignee when the RITM is commented. I have the following business rule which works fine when the assigned to is populated:
(function executeRule(current, previous /*null when async*/) {
var email_to =[];
var chg = new GlideRecord('change_request');
chg.addQuery('parent',current.sys_id+'');
chg.query();
while (chg.next()){
if (chg.assigned_to){
email_to.push(chg.assigned_to);
}
}
gs.eventQueue("change.commented", current, email_to.join(), gs.getUserName());
})(current, previous);
I need to know how to add an else{} statement to this script which will convert the assignment group members to a string and email them all if the change is unassigned. I have tried the following, but its not working:
else{
var list = current.assignment_group.u_managers.toString();
var listArr = list.split(',');
for (var i=0;i<listArr.length;++i) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',listArr[i]);
user.query();
if(user.next()){
email_to.push(user.sys_id.toString());
}
Any help greatly appreciated.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 06:25 AM
Hello,
Try this out and let me know
var email_to =[];
var chg = new GlideRecord('change_request');
chg.addQuery('parent',current.sys_id+'');
chg.query();
while (chg.next()){
if (chg.assigned_to){
email_to.push(chg.assigned_to);
}else{
var members = new GlideRecord('sys_user_grmember');
members.addEncodedQuery('group='+chg.assignment_group);
members.query();
while(members.next(){
email_to.push(members.user.toString());
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 06:31 AM
try below, (Just FYI, you can pass in sys id of group in event parm1 or parm2);
(function executeRule(current, previous /*null when async*/) {
var email_to = [];
var chg = new GlideRecord('change_request');
chg.addQuery('parent',current.sys_id);
chg.query();
while (chg.next()){
if (chg.assigned_to){
email_to.push(chg.assigned_to.sys_id.toString());
}else{
email_to.push(chg.assignment_group.sys_id.toString());
}
}
gs.eventQueue("change.commented", current, email_to.toString(), gs.getUserName());
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 07:03 AM
That simple! Thanks Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 08:06 AM
One further extension to this issue.
The business rule referred to in this thread runs against the sc_req_item table.I also have an event based notification that emails the user/assignment group, but this runs on the change_request table and uses the OOB change.itil.role template. Everything works as expected, in that the group or the assignee receive a notification email informing them that the change has been updated (via comments copied across the RITM). However, the notification displays the RITM number rather than the CHG number in the link
How can I get the notification to link directly to the change??