- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2025 12:15 AM - edited 02-01-2025 12:19 AM
Hi Community,
I have created a Script Include that returns sys_ids of HR cases. When I call it in a report, it returns sys_ids, but the report shows zero results.
PFA the script and report screenshot. Any suggestions?
Thanks!
Script -
var gr = new GlideRecord('sn_hr_le_case');
gr.addActiveQuery();
gr.setLimit(5000);
gr.query();
var filteredArr = []; // Array to store sys_ids
while (gr.next()) {
var hasActiveTask = false; // Flag for active HR tasks
var hasActiveRequest = false; // Flag for active SC requests
var hasActiveGroupOp = false; // Flag for active group operations
// Check for active HR tasks
var taskGr = new GlideRecord('sn_hr_core_task');
taskGr.addQuery('parent', gr.getValue('sys_id'));
taskGr.addActiveQuery();
taskGr.setLimit(1);
taskGr.query();
if (taskGr.hasNext()) {
hasActiveTask = true;
}
// Check for active SC requests
var reqGr = new GlideRecord('sc_request');
reqGr.addQuery('active', true);
reqGr.addQuery('parent', gr.getValue('sys_id'));
reqGr.setLimit(1);
reqGr.query();
if (reqGr.hasNext()) {
hasActiveRequest = true;
}
// Check for active Group Operations
var grpOpGr = new GlideRecord('some table);
grpOpGr.addQuery('active', true);
grpOpGr.addQuery('parent', gr.getValue('sys_id')); // Ensure Group Operation is linked to HR case
grpOpGr.setLimit(1);
grpOpGr.query();
if (grpOpGr.hasNext()) {
hasActiveGroupOp = true;
}
// Add HR case to array if it has NO active tasks, NO active requests, and NO active group operations
if (!hasActiveTask && !hasActiveRequest && !hasActiveGroupOp) {
filteredArr.push(gr.getValue('sys_id').trim());
}
}
return filteredArr;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2025 02:21 AM - edited 02-01-2025 02:22 AM
Hi ,
I have made the below changes now it is working fine
filteredArr.push(gr.sys_id + ',');
}
}
return filteredArr.toString();
Thanks ,
Astik T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2025 12:23 AM
Convert the array into string and then return it. Split the returned string with comma separation and convert it back into array in the script from where you are calling the script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2025 01:27 AM
Some query business rule is restricting the records since your sysIds are shown in the report.
Did you check table level READ ACL is blocking?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2025 02:21 AM - edited 02-01-2025 02:22 AM
Hi ,
I have made the below changes now it is working fine
filteredArr.push(gr.sys_id + ',');
}
}
return filteredArr.toString();
Thanks ,
Astik T