- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2020 10:57 PM
Hi All,
I want to update Parent record state when one or more child records state changed to Rework state then I need to update parent state also Rework,
Like wise I want to do it for 2 states : Rework and Reinstall.
Kindly help me how to achieve this.
Parent is Test Case table and Child is Test case steps table.
Thanks,
Lean S
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2020 10:10 AM
Hi,
Create an After Update BR
Filter conditions :-
State changes to Rework OR
state changes to Reinstall AND
parent is not empty
Try this code :-
(function executeRule(current, previous /*null when async*/) {
var recGa = new GlideAggregate('Table Name'); //GlideAggregate for getting the child records count
recGa.addQuery('parent', current.getValue('parent')) // quering the records having same parent
recGa.addQuery('state', current.getValue('state')); // quering state of the current child with other childs
recGa.addAggregate('COUNT');
recGa.query();
if (recGa.next()) {
var childCount = parseInt(recGa.getAggregate('COUNT'), 10); // getting the count of child records
if(childCount >= 1) { //checking if child count is greater than or equal to 1
var parentGr = current.parent.getRefRecord(); // getting the GlideRecord object of the parent record
parentGr.setValue('state', current.getValue('state')); //setting the state value
parentGr.update(); //updating the parent record
}
}
})(current,previous);
Note : please make changes in the code if field names are different.
Thanks,
Sourav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2020 10:10 AM
Hi,
Create an After Update BR
Filter conditions :-
State changes to Rework OR
state changes to Reinstall AND
parent is not empty
Try this code :-
(function executeRule(current, previous /*null when async*/) {
var recGa = new GlideAggregate('Table Name'); //GlideAggregate for getting the child records count
recGa.addQuery('parent', current.getValue('parent')) // quering the records having same parent
recGa.addQuery('state', current.getValue('state')); // quering state of the current child with other childs
recGa.addAggregate('COUNT');
recGa.query();
if (recGa.next()) {
var childCount = parseInt(recGa.getAggregate('COUNT'), 10); // getting the count of child records
if(childCount >= 1) { //checking if child count is greater than or equal to 1
var parentGr = current.parent.getRefRecord(); // getting the GlideRecord object of the parent record
parentGr.setValue('state', current.getValue('state')); //setting the state value
parentGr.update(); //updating the parent record
}
}
})(current,previous);
Note : please make changes in the code if field names are different.
Thanks,
Sourav

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2020 10:29 AM