- 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 07:24 AM
can you share your earlier script here? don't add screenshot
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:32 AM
function Stores_SI_AB(){
try{
var arr = [];
var locationRec = new GlideRecord('cmn_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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 07:34 AM
it makes sense showing the locations in report which have more than 3 incidents linked to it
why to have report on incident table?
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:45 AM
The condition is on location table, but I want to provide the incident details.
Example:
There are 3 locations
let's say
loc1, 4 incidents are from loc1
loc2, 2 incidents are from loc2
loc3, 6 incidents are from loc3
So, I want to query if the location contains 3+ incidents or not, if yes those incidents has to be shown.
From the example, it has to show only incidents from loc1 and loc3(4+6 = 10 incidents)
- 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