Script Include returns sys_ids, but the report shows zero results.

Astik Thombare
Tera Sage

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;

 

 

 

AstikThombare_0-1738397884488.jpeg

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Astik Thombare
Tera Sage

Hi ,

 

I have made the below changes now it is working fine 

 

 

  filteredArr.push(gr.sys_id + ',');  
    }  
}  

return filteredArr.toString();

 

 

 

Thanks ,

Astik T

View solution in original post

3 REPLIES 3

mohd_ansari03
Tera Contributor

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.

Ankur Bawiskar
Tera Patron
Tera Patron

@Astik Thombare 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Astik Thombare
Tera Sage

Hi ,

 

I have made the below changes now it is working fine 

 

 

  filteredArr.push(gr.sys_id + ',');  
    }  
}  

return filteredArr.toString();

 

 

 

Thanks ,

Astik T