Help with a Script please - tell me what I am doing incorrectly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 06:23 AM
We have a Scheduled Job that runs that will look for Incidents that are unassigned and will use the On-Call to assign those, but now we have a Group who does not want that to happen, so I am trying to exclude that group and not having much luck with the script.
assinOnCall() ;
function assinOnCall() {
var query = 'active=true^assignment_groupISNOTEMPTY^assigned_toISEMPTY^assignment_group!=dcfca1854f88f6c08dab0ad14210c7b6';
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.comments = "The assigned to was empty. This Incident was updated using the current on-call resource";
grInc.update();
} else {
return false;
}
}
}
function getOnCall(groupId) {
var returnAssignee = '';
var rota = new OnCallRotation() ;
var hasRota = rota.who(groupId) + '';
if(hasRota == 'true^assignment_group!=dcfca1854f88f6c08dab0ad14210c7b6') {
returnAssignee = rota.getPrimaryUser();
}
return returnAssignee;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 06:47 AM
You have to remove assignment group query from below part of code.
You are already excluding the group when querying the incidents.
function getOnCall(groupId) {
var returnAssignee = '';
var rota = new OnCallRotation() ;
var hasRota = rota.who(groupId) + '';
if(hasRota == 'true') {
returnAssignee = rota.getPrimaryUser();
}
return returnAssignee;
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 07:56 AM
Thanks for the Help Voona,
But the query is not preventing the Group Assigned to Assignment, it still occurs when the script runs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 10:30 AM
The Script still will not exclude a Group, can anyone please let me know what I am doing wrong please.
assinOnCall() ;
function assinOnCall() {
var query = 'active=true^assigned_to=NULL^assignment_group!=dcfca1854f88f6c08dab0ad14210c7b6';
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.comments = "The assigned to was empty. This Incident was updated using the current on-call resource";
grInc.update();
} else {
return false;
}
}
}
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
07-23-2024 01:39 PM
I am not aware of this concept to provide the logic.
I'll mention others who might be able to help.
@Ankur Bawiskar @Dr Atul G- LNG
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP