Need help with script to clean out deactivated users in the on-call scheduling calendar

alexbones
Tera Expert

One issue we are running into with the on-call calendar is that when a user is deactivated they are still active in the on-call calender rotation. HI indicated this is a bug that they will work out sometime in the future but don't know when.

My idea for a workaround is to remove them off the on-call rotation table in a scheduled job, but i am finding that the overall rotation now has gaps from where the user was. I know if you go into the groups rotation and save any change, the schedule will rebuild which would remove all the gaps in the schedule from the missing user. So I'm looking for a way to get the schedule to rebuild in my script. I am fairly new at scripting, but this is what I have so far:

//Clears out inactive users from the on-call rota

//table to remove records on

doit("cmn_rota_member");

function doit(table) {

      var gr = new GlideRecord(table);

      gr.addQuery('member.active', '=', 'false');

      gr.query();

      gr.deleteMultiple();

}

Thanks in advance for any help!

Alex

1 ACCEPTED SOLUTION

Try this in any sub prod instance first



var rotaSysID='';


var gr = new GlideRecord('cmn_rota_member');


gr.addQuery('member.active', '=', 'false');


gr.query();


while(gr.next())


{




rotaSysID=gr.roster.rota.toString();


gr.deleteRecord();




var getRelatedRota = new GlideRecord('cmn_rota');


if(getRelatedRota.get(rotaSysID))


{


getRelatedRota.setForceUpdate(true);


getRelatedRota.update();


}




}



This should trigger the business rule.


View solution in original post

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

Your script should clear out the inactive users from the table. Is it not working?



Additionally you can add a similar code on a business rule of sys_user table and whenever user becomes inactive, perform a similar operation. That would be a automated solution and you would not need to run the job after a one time clean up.


It does clear it out from the table, but when you run the on-call calendar report, it shows no one is on call where that user used to be leaving gaps in our on-call calendar.


I like your idea of running a business rule on the sys_user table. Is there a way to call another business rule on a different table? I just found that the On-call table has a business rule that rebuilds the schedule for a group every time the group rotation has a change, so that rule would shift the users to fill in the gaps. This is the piece my previous script was missing.   The only issue I see running the script on the sys_user table is referencing which group rotation the user is on and updating that group rotation with the change.



Here is the business rule that rebuilds the schedule after any update:



gs.include("OnCallRotation");


var rosterGR = new GlideRecord("cmn_rota_roster");


rosterGR.initialize();


rosterGR.addActiveQuery();


rosterGR.addQuery("rota", current.sys_id);


rosterGR.query();


while (rosterGR.next()) {


  updateRoster(rosterGR);


}



function updateRoster(rosterGR) {


  // Recompute the rotation schedules for the roster members


  var o = new OnCallRotation();


  o.computeRotationSchedules(rosterGR);



  gs.addInfoMessage("Rotation schedules for '" + rosterGR.name + " " + rosterGR.rota.name + "' have been updated");


}


Try this in any sub prod instance first



var rotaSysID='';


var gr = new GlideRecord('cmn_rota_member');


gr.addQuery('member.active', '=', 'false');


gr.query();


while(gr.next())


{




rotaSysID=gr.roster.rota.toString();


gr.deleteRecord();




var getRelatedRota = new GlideRecord('cmn_rota');


if(getRelatedRota.get(rotaSysID))


{


getRelatedRota.setForceUpdate(true);


getRelatedRota.update();


}




}



This should trigger the business rule.