Notify Assignment Group Manager when Assigned to is inactive

Shankar Manohar
Mega Guru

Dear All,

   I need to notify the Assignment group Manager every week once when the assigned to member of that group is inactive. 

I tried using a scheduled job with a script and the events. However, the notifications is not getting triggered at all.

 Any suggestions would be of great help.

 

Thanks

Shan

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Try this code. Now the event and notification should be on group table

 

var grGroup = new GlideRecord('sys_user_group');
grGroup.addQuery("manager.active",true);
grGroup.addQuery("active",true);
grGroup.query();
while(grGroup.next()){
var arr=[];
var inc= new GlideRecord("incident");
inc.addQuery('assigned_to.active',false);
inc.addQuery('assignment_group',grGroup.getValue('sys_id'));
inc.addQuery('incident_state','NOT IN','6,7');
inc.query();
while(inc.next())
{
arr.push(inc.getValue('number'));
}
if(arr.length>1){
gs.eventQueue("inactiveassigntoevent",grGroup,grGroup.manager.email,arr.join()); //here 4th parameter has comma separated incidents that are assigned to inactive users
}
}

View solution in original post

14 REPLIES 14

Shankar Manohar
Mega Guru

Hi Abhi,

  Actually, I want to notify the manager with all the incident numbers that were assigned to the inactive user for that assignment group. But can this be achieved writing the notification on the group table?

Because I have written my notification on the incident table and also the event on incident.

I will provide screenshots if required. 

 

Thanks

Shan

I would rather write a business rule on user table to check user got inactivated and query all incidents assigned to this user and email to the manager.

 

if you write script on incident table, there could be multiple users inactive and you wont know, to which manager you have to send the notification


Please mark this response as correct or helpful if it assisted you with your question.

Shankar Manohar
Mega Guru

Hi Sanjiv,

 

 This is my business case. 


When an "Assigned to" becomes inactive in ServiceNow the assignment group manager will recieve an email containing all incidents that are not in a resolved or closed state and are assign to the user who has been made inactive. This email notification should go out on a weekly basis.

 

So the BR is after Update on User Table

When to run : Active changes to False

in Script : Query the incidents assigned to the User

Notification: Incident Table 

Check Param 1 as in the Event Queue script

Does this sound good or have some changes

 

Thanks

Shan

I believe the tricky part is how will you know which all incidents are belongs to which assignment_group, so you may have to use GlideAggregate first to group the glide query result based upon the assignment_group and then run the gliderecord to collect the related incidents to trigger an email to that particular assignment_group manager. 

Abhinay Erra
Giga Sage

Try this code. Now the event and notification should be on group table

 

var grGroup = new GlideRecord('sys_user_group');
grGroup.addQuery("manager.active",true);
grGroup.addQuery("active",true);
grGroup.query();
while(grGroup.next()){
var arr=[];
var inc= new GlideRecord("incident");
inc.addQuery('assigned_to.active',false);
inc.addQuery('assignment_group',grGroup.getValue('sys_id'));
inc.addQuery('incident_state','NOT IN','6,7');
inc.query();
while(inc.next())
{
arr.push(inc.getValue('number'));
}
if(arr.length>1){
gs.eventQueue("inactiveassigntoevent",grGroup,grGroup.manager.email,arr.join()); //here 4th parameter has comma separated incidents that are assigned to inactive users
}
}