
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2018 01:19 PM
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
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 02:24 PM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 07:56 AM
Dear Mark,
Glad it was helpful.
I believe we need to make use of order field on the rota member table to pick up the correct member
Condition script
answer = script();
function script() {
returnFlag = false;
var gdt = new GlideDateTime();
var dow = gdt.getDayOfWeekLocalTime();
if (dow < 6) {
returnFlag = true;
}
return returnFlag;
}
Run this script:
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.orderBy('order'); // Member with lowest order is the one that is oncall.
grRota.query();
if(grRota.next()) {
returnAssignee = grRota.member + '';
}
return returnAssignee;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 08:48 AM
negative experience the same results
If we use Order then we would also have to use the Start Date of the Schedule
The rotation order will begin from the start date it was created
Found this script in the On-Call:Assign Workflow the Trigger Rules will use, would we now be able to use the bottom part of this script with your script?
gs.include("OnCallRotation");
//Get the assignment group from the input variable
//Assign the incident to right on-call resource
var rota = new OnCallRotation();
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();
}
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 08:51 AM
You are correct, we can use the method getPrimaryUser(); So if I merge this with the original script, it would look like below.
/*var rota = new OnCallRotation();
rota.who(group);
var currentOnCall = rota.getPrimaryUser(); */
Condition script
answer = script();
function script() {
returnFlag = false;
var gdt = new GlideDateTime();
var dow = gdt.getDayOfWeekLocalTime();
if (dow < 6) {
returnFlag = true;
}
return returnFlag;
}
Run this script:
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 rota = new OnCallRotation();
rota.who(groupId);
var returnAssignee = rota.getPrimaryUser();
}
return returnAssignee;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 09:31 AM
Anti,
Going backwards - stopped working - there was two error from last script, did I do something wrong?
var returnAssignee = rota.getPrimaryUser(); - 'returnAssignee' is already defined so I removed var
}
return returnAssignee;
}
} Unrecoverable syntax error - had a extra I removed it.
This is the Script I tried to run, did I break it?.
var rota = new OnCallRotation();
rota.who(group);
var currentOnCall = rota.getPrimaryUser();
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 rota = new OnCallRotation();
rota.who(groupId);
returnAssignee = rota.getPrimaryUser();
current.comments = gs.getMessage("This Incident assigned to was empty based on current on-call resource");
}
return returnAssignee;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 10:13 AM
Dear Mark,
Sorry I didnt test my code. Now I tested it. Condition script would remain the same as earlier. The 'run this script' would be below
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(groupId);
}
return returnAssignee;
}