If the assigned to user was inactive, then clear out the users name from the list of tasks assigned to him.

Feroz Khasim
Kilo Explorer

Hi Team,

 If the assigned to user was made inactive (in user record), then clear out the users name from the list of task's assigned to him.

How can I approach it, Please help me on this.

3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

HELLO @Feroz Khasim ,

YOU CAN WRITE A AFTER UPDATE BR ON SYS_USER TABLE 

where the condition can be like active changes to false 

then the script can be like below

var gr = new GlideRecord('task');
gr.addQuery('assigned_to',current.sys_id);
gr.query();
while(gr.next())
{
gr.assigned_to ="";
gr.update();
}

Hope this helps 

please mark my answer correct if this helps you

Yousaf
Giga Sage

Hi,

Try this 

(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()){
    inc.assigned_to = "";

    inc.update();
  }
})(current, previous);

 

 

Reference : business rule when a user is inactive

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Jaspal Singh
Mega Patron
Mega Patron

Hi Feroz,

You need an after update BR on User table that runs when Active | changes to  | false with script as below.

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

    var setemptyassignedto = new GlideRecord('task');
    setemptyassignedto.addQuery('active', 'true');
    setemptyassignedto.addQuery('assigned_to', current.sys_id);
    setemptyassignedto.query();
    while (setemptyassignedto.next()) {
        setemptyassignedto.assigned_to = '';
        setemptyassignedto.work_notes='Assiged to changed to empty as user is inactive';
        setemptyassignedto.update();
    }

})(current, previous);

For existing records try below as background script.

 var setemptyassignedto = new GlideRecord('task');
 setemptyassignedto.addQuery('active', 'true');
 setemptyassignedto.addQuery('assigned_to.active', 'false');
setemptyassignedto.setLimit(10);//do for 10 records first 
setemptyassignedto.query();
while (setemptyassignedto.next()) {
gs.print('Records updated are '+setemptyassignedto.number);
setemptyassignedto.assigned_to = '';
setemptyassignedto.work_notes='Assiged to changed to empty as user is inactive';
setemptyassignedto.update();
    }