whenever parent is closed, child should also close automatically

ShivaK548811677
Tera Contributor

How to do this in flow design.

7 REPLIES 7

SD_Chandan
Kilo Sage

Hi @ShivaK548811677 ,

I am doing on change task via BR 

SD_Chandan_0-1755834039462.png

 

(function executeRule(current, previous /*null when async*/) {
   var CLOSED = 3;      // Closed Complete
   var CANCELLED = 4;   // Cancelled
   // Only check when state is changing
   if (current.state != previous.state) {
       // ---- 1. Block if previous tasks are not closed or cancelled ----
       if (current.change_request && current.order) {
           var taskGR = new GlideRecord('change_task');
           taskGR.addQuery('change_request', current.change_request);  // Same Change
           taskGR.addQuery('order', '<', current.order);               // Lower order
           taskGR.addQuery('state', 'NOT IN', [CLOSED, CANCELLED]);    // Not Closed/Cancelled
           taskGR.query();
           if (taskGR.hasNext()) {
               gs.addErrorMessage("You cannot move this task until all previous tasks are Closed or Cancelled.");
               current.setAbortAction(true);
               return;
           }
       }
       // ---- 2. Block if trying to close and Change Request is not in Implement stage ----
       if (current.state == CLOSED) {
           var change = current.change_request.getRefRecord();
           if (change && change.state != '-1') { // 'implement' is the internal value
               gs.addErrorMessage("You cannot close this task until the Change Request is in the Implement stage.");
               current.setAbortAction(true);
           }
       }
   }
})(current, previous);

If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'.


Thank you
Chandan

Ankur Bawiskar
Tera Patron
Tera Patron

@ShivaK548811677 

why would parent close first and then child?

It's an easy requirement for flow.

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Bhuvan
Tera Sage

@ShivaK548811677 

 

Create a flow with below condition,

 

1. Trigger is when Incident record is updated with State == 'Closed'

2. Check IF condition whether child incident count is > 0

3. If yes, lookup records of child incidents by using condition Parent Incident.Number is same as Trigger Incident number

4. Update Multiple records and set resolution notes, resolution code and State == closed fields for the lookup records

Bhuvan_1-1755841343402.png

Below is a sample scenario for testing,

Bhuvan_0-1755841332134.png

Bhuvan_2-1755841518727.png

Bhuvan_0-1755841736221.png

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan