Show records grouped by location where location is more than 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
This is similar to this thread Show group by records with more than 1 record - ServiceNow Community.
I am struggling to find a resource of documentation that will guide me to create an incident report that is grouped by location and only show records with multiple occurrences on the last 30 days.
This is to identify locations with multiple incidents on the last 30 days.
Will appreciate any assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi @chanp,
Are you specifically looking for a report based on the incident table? If you do not necessarily need the incident table and only want to focus on locations with multiple incidents within the past 30 days, you can achieve this by creating a report on the location table.
All Incident Locations:
Locations with more than one incidents:
Here are the steps to achieve this:
1. Navigate to Platform Analytics Administration > Usage and governance > Reports, Click New.
2. Set Up the Report Source:
- Report Name: Locations with multiple incidents on the last 30 days
- Source Type: Table
- Table: Location [smn_location]
3. Set the Related List Conditions:
In the Related List Conditions section, configure as follows:
- Set the filter to: Greater than 1 table records are related to a record on Location
- Related List Table: Incident > location
- Filter Conditions on Location:
- Created on Last 30 Days
This ensures that only Location with more than 1 Incidents in the last 30 days are returned.
4. Select the Report Type:
- Go to the Type tab
- Choose List as the report format
5. Configure Config tab:
- Go to the Configure tab
- Set Group By: None
6. Save the report.
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Create report > List > Select Columns (ex. Location, Created) > Group by Location. Then make a filter to only include records created on the last 30 days. This will show a list of incidents grouped by location. From this list, need to exclude records with a count of 1 like the example below, Location A and C should be excluded.
Location: A (1 )
Location: B (2 )
Location: C (1 )
Location: D (3 )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
16 hours ago
Hi @chanp,
To create a report that groups incidents by location and only shows locations with multiple incidents in the last 30 days, you can follow these steps:
1. Create a Script Include "GetLocationsWithMultipleIncidents" with Glide AJAX enabled and Sandbox enabled. Use the following script:
var GetLocationsWithMultipleIncidents = Class.create();
GetLocationsWithMultipleIncidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocationIds: function() {
var ids = [];
var ga = new GlideAggregate('incident');
ga.addNotNullQuery('location');
ga.groupBy('location');
ga.addAggregate('COUNT');
ga.query();
while (ga.next()) {
var count = parseInt(ga.getAggregate('COUNT'));
if (count > 1) {
ids.push(ga.getValue('location'));
}
}
if (ids.length > 0) {
return ids.join(',');
}
return '';
},
type: 'GetLocationsWithMultipleIncidents'
});
This Script Include aggregates incidents by location over the last 30 days and returns only those locations where the incident count is greater than one.
2. Navigate to Platform Analytics Administration > Usage and governance > Reports, Click New.
3. Set Up the Report Source:
- Report Name: Locations with multiple incidents on the last 30 days
- Source Type: Table
- Table: Incident [incident]
4. Apply Filter Conditions
Location . Sys ID > is one of > javascript:new global.GetLocationsWithMultipleIncidents().getLocationIds();
Created > on > Last 30 days
This ensures that only Location with more than 1 Incidents in the last 30 days are grouped.
4. Select the Report Type:
- Go to the Type tab
- Choose List as the report format
5. Configure Config tab:
- Go to the Configure tab
- Set Group By: Location
6. Save the report.
Outcome:
All Incident Locations:
Locations with more than one incidents:
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @chanp ,
Refer below link
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand