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-25-2024 04:16 AM
Thanks for adding me @Voona Rohila but I am not a developer.
@Sandeep Rajput @AshishKM any help.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:50 AM
Hi @Mark Lanning ,
Can you please confirm about the group which you are trying to exclude.
Function assinOnCall is excluding the below group and all incident assigned to this group should not part of while loop. ( that is expectation )
assignment_group!=dcfca1854f88f6c08dab0ad14210c7b6
You can try this filter condition in the List View and check the result data.
If List View is giving same result then check if this group has any parent group configured.
Please test and share the result.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 11:40 AM - edited 07-25-2024 11:44 AM
AshishKM,
Yes, there is a Parent Group. I did get the query from the List View.
Should I be doing something different?
This is the Post back in 2018 when I asked help to create this, only difference now, is I have a Group who want to be excluded, where the Assigned to remain empty.
Solved: Update Incidents where the Assigned to is empty du... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 10:16 AM
Just checking if issue still there.
If the exlucing group has parent group then that also need to exclude, otherwise parent is allowed and all child group record will be visible.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution