i'm writing a business rule when a user is inactive then all the incidents under his name should be reassigned to his group manager and donno where i am going wrong. Please help me out.

Nagendra11
Kilo Expert

i am trying to write a business rule suppose if the user becomes inactive reassign all his incidents to his group manager.

After (Update)

Active changes to false :

(function executeRule(current, previous /*null when async*/) {

var inc =new GlideRecord('incident');
var user = current.sys_id;

inc.addQuery('assigned_to',user);
//inc.addQuery('assignment_group',group);
gs.logs('#000');
inc.query();

while(inc.next()){
var aa = new GlideRecord('sys_user_group');
var man = user.sys_user_group.manager;
aa.addQuery('User',user);
gs.logs('#002');
aa.query();

while(aa.next()){
inc.assigned_to = man;
inc.update();

}
}

})(current, previous);

 

Please help me out. let me know where i am going wrong or if the whole thing is wrong.

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Try this out:

(function executeRule(current, previous /*null when async*/) {
  var user = current.getValue("sys_id");  //should usually use a string version of the data
  var inc = new GlideRecord("incident");
  //added extra filter so closed/cancelled records are not re-assigned
  inc.addEncodedQuery("active=true^assigned_to=" + user);
  inc.query();
  while(inc.next()){
    manager = inc.assignment_group.manager.toString();
    if (manager){
      inc.assigned_to = manager;
    } else {
      inc.assigned_to = "";
    }
    inc.update();
  }
})(current, previous);

This will set the "Assigned to" field to the current Assignment group's Manager.  If there is no Manager, will simply clear the Assigned to field.  You would have to deal with that somehow.

View solution in original post

7 REPLIES 7

Jim Coyne
Kilo Patron

Try this out:

(function executeRule(current, previous /*null when async*/) {
  var user = current.getValue("sys_id");  //should usually use a string version of the data
  var inc = new GlideRecord("incident");
  //added extra filter so closed/cancelled records are not re-assigned
  inc.addEncodedQuery("active=true^assigned_to=" + user);
  inc.query();
  while(inc.next()){
    manager = inc.assignment_group.manager.toString();
    if (manager){
      inc.assigned_to = manager;
    } else {
      inc.assigned_to = "";
    }
    inc.update();
  }
})(current, previous);

This will set the "Assigned to" field to the current Assignment group's Manager.  If there is no Manager, will simply clear the Assigned to field.  You would have to deal with that somehow.

Hello Jim,

thank you for answering my query. Works like Charm :).

You are welcome.