Update Incidents where the Assigned to is empty due to no On-Call person was Scheduled for the Assignment Group

Mark Lanning
Tera Guru

Issue -

Due to the On-Call Calendar Schedule being setup for 8 to 4:30 with someone scheduled to assign a person to an Incident

The only option for the On-Call Rota is when an incident is create outside a schedule with no Assigned To is to update the Assignment Group and leave the Assigned to empty.

The On-Call Rota will not rerun again the next business day to find those incidents that came in after hours

So we are looking to create a Scheduled Job to run at 8:00 am to find any Active Incidents with the Assigned to is empty then update the Assigned to with the Current On-Call Person for that Assignment Group

Would have to Query the Incident and the cmn_rota Tables

From the Incident table would have to guery any active is true and assigned_to is empty incidents - Would think we want to return Number and Assignment Group

From the Rota cmn_rota table would need to query the matching assignment group then return the current on-call rota member

Would then need to have the current on-call rota member placed in the incident assigned to field

This in turn would update Incidents where the Assigned to was empty with the current On-Call person for that Assignment Group on the next business day.

And to add even more twist - Can it be scheduled to only occur Monday thru Friday would want to exclude weekends

Is this something that can be done?

Mark

1 ACCEPTED SOLUTION

Anil,


You are awesome!


Thank You again for your Help.



Final Script that work great.



assinOnCall() ;



function assinOnCall() {


var query = 'assignment_groupISNOTEMPTY^assigned_toISEMPTY';


var grInc = new GlideRecord('incident');


grInc.addEncodedQuery(query);


grInc.query();


while (grInc.next()) {


var group = grInc.assignment_group.sys_id + '';


var assigned_to = getOnCall(group) + '';


if(assigned_to != '') {


grInc.assigned_to = assigned_to;


grInc.update();


}


}


}



function getOnCall(groupId) {


var returnAssignee = '';


var rota = new OnCallRotation() ;


var hasRota = rota.who(groupId) + '';


if(hasRota == 'true') {


returnAssignee = rota.getPrimaryUser();


}


return returnAssignee;


}


View solution in original post

23 REPLIES 23

Dear Mark,



Does that group have Oncall schedules and oncall members in this table(cmn_rota_member) for that group


Yes


This Script would pull and Update the Incident with a member from the Group / it's was not the On-Call primary User



assinOnCall() ;



function assinOnCall() {


var query = 'assigned_to=NULL';


var grInc = new GlideRecord('incident');


grInc.addEncodedQuery(query);


grInc.query();


while (grInc.next()) {


var group = grInc.assignment_group;


grInc.assigned_to = getOnCall(group);


grInc.update();


}



function getOnCall(groupId) {


var returnAssignee = '';


var query = 'roster.rota.group=' + groupId +'^roster.active=true^memberISNOTEMPTY';


var grRota = new GlideRecord('cmn_rota_member');


grRota.addEncodedQuery(query);


grRota.query();


if(grRota.next()) {


returnAssignee = grRota.member + '';


}


return returnAssignee;


}


}


OK great, in that case lets try to update this version of script and make it work for your requirement, so do you know which user should be the assignee, as currently it picks up the first one?



We need to find out how to identify the user in cmn_rota_member who should be the assignee.. Can you check that in the table and see if you can arrive at a logic?


Mark Lanning
Tera Guru

Anil,


This should be fun.


Is it possible we need to refer back to one of these? OnCallRotaion or SncOnCallRotation or Update Rotation Schedules (Member)



Workflow - On-Call: Assign


To find a Schedule it will use this script:


answer = ifScript();


function ifScript() {


var rota = new SNC.OnCallRotation();   // Pulling from a Script Include


var gdt   = new GlideDateTime();


var escalationPlan = rota.getEscalationPlan(vars.assignment_group.sys_id.toString(), gdt);


      if (JSUtil.nil(rota) || JSUtil.nil(rota.getCurrentRotaID())) {


              return 'no';


      }


      return 'yes';


}


The next step of the Workflow it will find the PrimaryUser


gs.include("OnCallRotation");   // Pulling from a Script Include


//Get the assignment group from the input variable


//Assign the incident to right on-call resource


var rota = new OnCallRotation();   // Pulling from a Script Include


rota.who(workflow.inputs.assignment_group + '');


var currentOnCall = rota.getPrimaryUser();


workflow.scratchpad.assignment_group_id = workflow.inputs.assignment_group;


workflow.scratchpad.current_on_call_id = currentOnCall;


//Only assign if there is someone is on_call & assigned_to is empty


if(currentOnCall && current.assigned_to.nil()) {


current.assigned_to = currentOnCall;


current.comments = gs.getMessage("Incident assigned based on current on-call resource");


current.update();


}



Looking at Script Includes:


OnCallRotationCalculator - Will Calculate the Order and the Start Date of the Calendar to rotate the Primary On-Call Person.


**OnCallRotaion - Group on-call rotation convenience wrapper class - to use in your business rules:


gs.include("OnCallRotation");


var rota = new OnCallRotation(current);


**SncOnCallRotation - Legacy wrapper to maintain old @GlideScriptable calls that have been migrated to use reflection rhino prefixes


whoIsOnCall: function(groupIds, rotaIds, rosterIds, dateTime) {


return this.getEscalatees(groupIds, rotaIds, rosterIds, dateTime);


OnCallRotationRecalc - Recalculate OnCall Rotation Schedules. // Pulling from a Business Rules


Called from 'Update Rotation Schedules' business rules on cmn_rota_member & cmn_rota_roster.


**OCRotaMember is Read Only - Class to represent a cmn_rota_member record for on-call scheduling.



Looking at Business Rules


Update Rotation Schedules (Member) - doing this from the cmn_rota_member table


if (!GlideTransaction.get())


new OCRotaMember().recalculate(current, previous);


else if (GlideTransaction.get().getRequestParameter("sysparm_form") != "m2m")


new OCRotaMember().recalculate(current, previous);



Mark


Would you like to join me on slack. We can meet at around 12 PM PST and crack this.


Create Account | Slack