Business Rule - Close all Child record when Parent Close
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2022 03:09 PM
Dear all,
I have created a business rule to Close all Child Records when Parent is Close but if there is any Open task on the Child record the action will be aborted. It is not working. Could someone help me to take a look?
I would appreciate you help.
______________________________
(function executeRule(current, previous /*null when async*/ ) {
var gs = new GlideRecord('x_g_afi_mcms_incident_case_task');
gs.addQuery('parent.parent', current.sys_id);
gs.query();
while (gs.next()) {
if (current.state != 3) {
gs.addErrorMessage('Cannot close Misconduct case with open Incident case task');
gs.addInfoMessage(gr.number);
current.setAbortAction(true); //abort the record
} else if (current.state == 3) {
var gr = new GlideRecord('x_g_afi_mcms_incident_case');
gr.addQuery("parent", current.sys_id);
gr.query();
while (gr.next()) {
gr.status = "close_out";
gr.update();
}
}
}
})(current, previous);
____________________________________

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2022 03:24 PM
Hi,
First can you change gs to anything else.
Refer to this if this could help and let me know
I want to close all child incidents after closing parent incident?
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2022 04:07 PM
Hi Yousaf,
I can make all child records close when parent close but I have another condition. If there is an open task in the Child, then abort the record with popup message.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2022 04:20 PM
Found this can you please modify and let me know if it works.
preventclose();
Make a before Update Business rule with this code.I havnt tested it but looks ok to me 🙂
function preventclose(){
//Build a query to look up the children
var child = new GlideRecord("incident");
child.addQuery("parent",current.sys_id);
child.addQuery("state","!=",7); //add ur condition here
child.query();
if(child.next()){
current.state=previous.state;
current.setAbortAction(true);
gs.addErrorMessage('Please close child !');
}
}
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2022 05:56 AM
Hi Yousaf,
In my case, they are 3 levels.
Parent
Child_1: Child to the Parent
Child_2 : Child to Child_1
The condition is when Parent Close:
- Set all Child_1 records to close Only if there is no Open Child_2 records.
- If there is a open record in Child_2 then get an popup message and set AbortAction on both Parent & Child_1