Group by(location field) incidents in flow designer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 10:33 PM
Hi everyone,
I need some assistance with creating a flow in ServiceNow using Flow Designer. My goal is to make group incidents of x sub category by location and, if there are more than 5 incidents in the same location and sub category, create a parent incident and link the minor incidents to this parent incident. Here's what I'm trying to achieve:
1. Group Incidents by Location 1: Retrieve all open incidents with sub category x and group them based on their location.
2. Check Incident Count: For each location, check if there are more than 5 incidents.
3. Create Parent Incident: If any location has more than 5 incidents with sub category x, create a new parent incident.
4. Link Minor Incidents: Update each of the minor incidents in that category to set the newly created parent incident as their parent.
How can I achieve this,
Thanks in Advance.
Raj.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 01:51 AM
Hi,
This can be done in Flow Designer, but one piece is hard to accomplish, and that is the grouping of records.
Flow Designer has (currently) no easy way of doing this, so that part will have to be a custom action that you create/run, which checks records and returns a result set on which locations contains more than 5 records.
Do you still want to proceed?
The alternative is a script of some sort that does the whole thing instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 02:01 AM
Thanks Olan,
I've have tried with the custum script, but I didn't get.
Can you please provide sample script for script action in flow designer.
I will trigger this flow for every 5 hrs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 02:39 AM
Something like this would work to retrieve and send back results on records/locations that has more than 4 records grouped by category.
Do note, that I haven't taken into account if you should filter out records that already has a parent incident.
// replace this variable with an input parameter when you create your custom action
var categorySelection = 'inquiry';
// the locations variable will contain a commaseparated list of all records that has more than 4 open incident on a given category
// your output from the custom action should contain it's results for further processing
var locations = getIncidentsLocations(categorySelection);
//gs.info('locations with more than 4 records: ' + locations);
function getIncidentsLocations(category){
var arrResult = [];
var incGA = new GlideAggregate('incident');
incGA.addActiveQuery();
incGA.addQuery('category', category);
incGA.addQuery('location', '!=', ''); // if you want to filter out empty locations
incGA.groupBy('location');
incGA.addAggregate('COUNT');
incGA.query();
while (incGA.next()){
//gs.info('Location: ' + incGA.getValue('location'));
//gs.info('Location count: ' + incGA.getAggregate('COUNT'));
if (parseInt(incGA.getAggregate('COUNT'), 10) > 4){
arrResult.push(incGA.getValue('location'));
}
}
return arrResult;
}