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

alexbones
Tera Expert

This works great, thank you!!!