How to Automatically Close Child Incidents When Parent Incident is Closed via UI Action

vaishali231
Tera Contributor

Hi Community,

I have a requirement where, when a parent Incident is closed using a UI Action, the system should automatically:

Close all associated child Incidents (those with the parent value set).

Update each child Incident with a work note, similar to the one entered in the parent.

Could someone guide me on how to approach this?
Should this logic be added in the UI Action script of the parent? And how can I best loop through and update all child records with the parent's work note?

Any sample scripts or best practices would be appreciated.
Thanks in advance

14 REPLIES 14

nityabans27
Mega Guru

Hi @vaishali231 ,

Assumptions

  • Work note is input during the parent closure via a custom field (e.g., u_closure_note), or UI Action prompts the user.

  • No client/server input flow here — this is fully server-side.

  • This logic is triggered only when the parent is being closed from the UI Action.

UI Action script

// Validate closure note
if (!current.u_closure_note) {
gs.addErrorMessage("Closure note is mandatory.");
action.setRedirectURL(current);
return;
}

// Close parent incident
current.state = 7; // Closed
current.work_notes = current.u_closure_note;
current.update();

// Close child incidents
var childGR = new GlideRecord('incident');
childGR.addQuery('parent', current.sys_id);
childGR.query();
while (childGR.next()) {
childGR.state = 7; // Closed
childGR.work_notes = 'Closed via parent. Note: ' + current.u_closure_note;
childGR.update();
}

gs.addInfoMessage("Parent and all child incidents closed.");
action.setRedirectURL(current);

Please try this and accept it as solution and mark it helpful if found useful.

Thanks and regards,
Nitya Bansal

nemamuskan
Tera Contributor
function demoChildClose()
{
    var answer=confirm("Do you really want to parent and close child incident?");
    if(answer==true)
    {
		g_form.setValue('state', 7);
		g_form.setValue('close_code','Solved (Permanently)');
		g_form.setValue('close_notes', 'Closed from script');
		g_form.save();
        gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
    }
} // you should close the client side code here

if(typeof window == 'undefined')
    runServerCode();

function runServerCode(){
    var gr =new GlideRecord('incident');
    gr.addQuery('parent_incident',current.sys_id);
    gr.query();
    while(gr.next())
    {
        gr.setValue('state', 7);

        gr.setValue('close_code','Solved (Permanently)');

        gr.setValue('close_notes', 'Closed from script');
        gr.update();
    }
    action.setRedirectURL(current);
}

Hello @vaishali231 ,

 

Please try above in the UI action script with action name as "sys_demoaction" and onclick function as "demoChildClose();"

 

Please find the attached Screenshot as well for your reference.

This way you can close parent and child incident with UI action. I have tried and tested it works for me as well as you can do miner customization that are required or reach out to me, I can definitely help.

 

Please Mark my answer as helpful if it helps.

Thanks and Regard,

Muskan.

 

Hello @vaishali231,

 

Greetings of the day!!

 

Just wanted to check if my reply answer was helpful to you and answers your question?

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

Thanks, and Regards,

Muskan Nema

Mohammad Danis1
Giga Guru

Hi @vaishali231 ,

Hope you are doing good.

Did my reply answer your question?

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

Regards,
Mohammad Danish

Shubham_Jain
Mega Sage

@vaishali231 

 

1. Create a UI Action on the incident table

  • Condition: current.parent_incident.nil() == false && current.state != 'Closed'
  • Action Type: Form Button
  • Name: Close Parent and Children

2. Sample Script for the UI Action

// Close the parent incident
current.state = 7; // Closed
current.work_notes = "Parent incident closed. Closing child incidents.";
current.update();

// Get the parent's work note
var parentWorkNote = current.work_notes;

// Find and update child incidents
var childGR = new GlideRecord('incident');
childGR.addQuery('parent_incident', current.sys_id);
childGR.query();

while (childGR.next()) {
    childGR.state = 7; // Closed
    childGR.work_notes = "Closed due to parent incident closure. Parent note: " + parentWorkNote;
    childGR.update();
}

Best Practices

  • Use GlideRecord for querying child incidents.
  • Always check for current.parent_incident to avoid errors.
  • Consider adding logging or notifications if needed.

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain