- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Within my project, I want to calculate the number of child incidents attached with a parent incident and also want to add it to a report for my personal use in a dashboard where it will show, all the child incident details attached with parent incident.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SayaniC51691220 ,
You may do it in two ways.
Firstly we may do it in Dashbaord by using Group By Parent and it will show all the child incident in a dropdown format.
Secoundly you may use a glideAggregate to calculate the number of child incident attached with a parent incident and it will exclude the incident where the parent is empty.
var gr = new GlideAggregate('incident');
gr.addQuery('parent','!=','');
gr.addAggregate('COUNT');
gr.groupBy('parent');
gr.query();
while(gr.next()){
gs.info("Parent Incident "+gr.parent.number + ' contains : ' + gr.getAggregate('COUNT')+" child incident");
}
if you find it helpful please mark it as helpful and accept the solution.
Regards,
Sagnic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SayaniC51691220 ,
You may do it in two ways.
Firstly we may do it in Dashbaord by using Group By Parent and it will show all the child incident in a dropdown format.
Secoundly you may use a glideAggregate to calculate the number of child incident attached with a parent incident and it will exclude the incident where the parent is empty.
var gr = new GlideAggregate('incident');
gr.addQuery('parent','!=','');
gr.addAggregate('COUNT');
gr.groupBy('parent');
gr.query();
while(gr.next()){
gs.info("Parent Incident "+gr.parent.number + ' contains : ' + gr.getAggregate('COUNT')+" child incident");
}
if you find it helpful please mark it as helpful and accept the solution.
Regards,
Sagnic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I've tried your code and attaching the relevant screenshot.
It solved my purpose.
Thanks,
Sayani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Its_Sagnic
I've tried your solution and here I'm attaching the relevant screenshot.
This is helpful, it solved my purpose.
Thanks,
Sayani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You cannot easily report on "Count of Child Incidents" unless that number is stored in a field on the Parent Incident.
-
Create a Field:
Go to the Incident table.
Create a new integer field named u_child_incident_count (Label: Child Incident Count). -
Create a Business Rule:
Table: Incident [incident]
When: AFTER
Insert: Checked | Update: Checked | Delete: Checked
Filter Conditions: Parent Incident changes (This ensures it only runs when relationships change).Advanced Script:
(function executeRule(current, previous /*null when async*/) { // 1. Identify the Parent(s) we need to update // We check both current and previous to handle cases where an incident is moved FROM one parent TO another. var parentsToUpdate = []; if (current.parent_incident && !current.parent_incident.nil()) { parentsToUpdate.push(current.parent_incident.toString()); } if (previous.parent_incident && !previous.parent_incident.nil() && previous.parent_incident.toString() !== current.parent_incident.toString()) { parentsToUpdate.push(previous.parent_incident.toString()); } // Deduplicate the array (optional but good practice) var uniqueParents = new ArrayUtil().unique(parentsToUpdate); // 2. Loop through parents and recalculate count for (var i = 0; i < uniqueParents.length; i++) { var parentID = uniqueParents[i]; var agg = new GlideAggregate('incident'); agg.addQuery('parent_incident', parentID); agg.addAggregate('COUNT'); agg.query(); var count = 0; if (agg.next()) { count = agg.getAggregate('COUNT'); } // 3. Update the Parent Record var parentInc = new GlideRecord('incident'); if (parentInc.get(parentID)) { parentInc.u_child_incident_count = count; // setWorkflow(false) prevents this update from triggering other recursive business rules parentInc.setWorkflow(false); parentInc.update(); } } })(current, previous);
then create a standard list report on the Incident table
Happy to help! ‌‌
To help others in the community find this solution, kindly mark this response as the Correct Answer ‌‌ and Helpful‌‌.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
