- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 05:50 AM - edited 07-18-2023 05:51 AM
Hi,
I have a requirement to provide a report with incidents details where a location contains more than 3 incidents.
The Below snip is from incident table grouped by locations, hence I wanna give a report that contains only the incidents from highlighted locations( location contains >= 3 Incidents)
For test, I tried that from Fix Script I'm getting the output as expected. But when I call the same code from script include I'm getting only the incidents from first location. Here I'm providing the details of it.
FIX SCRIPT:
OUTPUT:
SCRIPT INCLUDE:
CALLING THE SCRIPT INCLUDE IN FIX SCRIPT:
OUTPUT:
Can anyone please help me to fix this issue.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 07:49 AM
got it
so update as this
function Stores_SI_AB(){
try{
var arr = [];
var locationRec = new GlideRecord('cmn_location');
locationRec.query();
while (locationRec.next()) {
var inc = new GlideRecord('incident');
inc.addEncodedQuery('location.sys_id=' + locationRec.sys_id);
inc.query();
var count = inc.getRowCount();
if (count > 3) {
while(inc.next()){
arr.push(inc.getUniqueValue());
}
}
}
return arr.toString();
}
catch(ex){
gs.info(ex);
}
}
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
07-18-2023 06:02 AM
the report should be client callable and something like this
function checkRecords(){
try{
// your code here
return array;
}
catch(ex){
gs.info(ex);
}
}
How to call it in report condition?
1) create report on incident table
2) add the filter condition as this
sys_id [IS ONE OF] javascript: checkRecords()
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
07-18-2023 06:21 AM
Hi @Ankur Bawiskar ,
Thanks for your time.
I tried your suggestion, even though I'm getting only one location's incidents.
Script Include:
Report:
Kindly correct me if I misplaced the return value.
Thanks
Aruna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 06:53 AM
try this once
function checkRecords(){
try{
var arr = [];
var locationRec = new GlideRecord('location');
locationRec.query();
while (locationRec.next()) {
var inc = new GlideAggregate('incident');
inc.addEncodedQuery('location.sys_id=' + locationRec.sys_id);
inc.query();
var count = inc.getRowCount();
if (count > 3) {
arr.push(inc.getUniqueValue());
}
}
return arr;
}
catch(ex){
gs.info(ex);
}
}
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
07-18-2023 07:19 AM
The condition is not fetching the sys_id's, instead showing the callback function(highlighted in 2nd snip). Tried to change 12th line with getValue('sys_id') but no luck.