- 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-21-2020 11:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2020 11:55 PM
Hi Lean,
Create After Update Business Rule on Test case Step table
Set the condition as State Changes
var gr = new GlideRecord('<Table name of test case table>');
gr.addQuery('sys_id', current.parent);
gr.query();
if(gr.next()) {
if(current.state.ChangesTo(<choice value of Rework>)
gr.state = <choice value of Rework>;
if(current.state.ChangesTo('<choice value of Reinstall>)
gr.state = <choice value of Reinstall>;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2020 09:14 AM
Hi,
I have used the code, but did not work for me , below is as saved in my script:
var gr = new GlideRecord('tm_test_instance');
gr.addQuery('sys_id', current.parent);
gr.query();
if(gr.next()) {
if(current.state.ChangesTo('rework'))
gr.state = 'rework';
if(current.state.ChangesTo('reinstall'))
gr.state = 'reinstall';
gr.update();
}
Thanks,
Lean S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2020 08:05 PM
Hi Lean,
You have to check the second line of the code.
Check which field on test case step table is linking to test case table. There would be any reference field on test case step table that must be referring to test case table.
In the second line of the code, instead of current.parent you have to write current.<field name referring to test case table>