- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 08:20 AM
I created a field called Child Count in the MIM scope.
Basically I want a business rule that add's one every time a Child is Added or Subtracts one if a child is removed.
Basically I want the Child Case related list counted. Any ideas?
Solved! Go to Solution.
- Labels:
-
Customer Service Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 10:55 AM
I tested this in my PDI. It is an after insert/update business rule which is one of the occasions where you can have an update() in the BR. In the when to run tab I have my condition as parent changes this way it can update the count if you remove a child case because it was added by accident. Then I have the following code.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var sysID = '';
if (current.getDisplayValue('parent') == ''){ //update count if case removed
sysID = previous.getValue('parent');
}
else { //update count if case added
sysID = current.getValue('parent');
}
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id', sysID);
gr.query();
if (gr.next()) {
gr.u_child_count = getCount(sysID);//get the count thought the below function
gr.update();
}
//function to get count thought GlideAggregate as using glide record to count can cause pour performance.
function getCount(sysID) {
var count = new GlideAggregate('sn_customerservice_case');
count.addQuery('parent', sysID);
count.addAggregate('COUNT');
count.query();
if (count.next()) {
return count.getAggregate('COUNT');
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2022 08:01 PM
Thanks this is really helpful but the problem is when we delete the child case. Still looking for a way to solve that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 11:10 AM
Dude!! thanks !! works great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 06:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 07:44 AM
For the cases that are not closed you could remove one of the child cases and add it back. If you want historical data on close cases we could convert the script I gave you and run it in the scripts background.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 08:55 AM
Yea there are too many of them to do manually...so I need to groom at least the Open ones.
This is what I have...
When to Run:
Major Case State = Accepted
State Is Not One Of Cancelled or Closed
Advanced
var sysID = '';
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('sys_id', sysID);
gr.query();
if (gr.next()) {
gr.u_child_count = getCount(sysID);//get the count thought the below function
gr.update();
}
//function to get count
function getCount(sysID) {
var count = new GlideAggregate('sn_customerservice_case');
count.addQuery('parent', sysID);
count.addAggregate('COUNT');
count.query();
if (count.next()) {
return count.getAggregate('COUNT');
}
}
Is it this simple?