Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Prevent Incident Closure if Child Task is Active

Kusuma Sai
Mega Guru

Hi,

If related child 'Incident_task' is Active, prevent the Incident Resolved/Closed.

tried with Before BR and Script Include and OnSubmit CS also, but not working as expected- suggest

KusumaSai_0-1749815259324.png

 

KusumaSai_1-1749815326928.png

KusumaSai_2-1749815367768.png

 

 


 @Ankur Bawiskar 

 

1 ACCEPTED SOLUTION

prudhviraj1
Tera Guru

Hi @Kusuma Sai ,

 

Try to use Before Update BR only.

(function executeRule(current, previous /*null when async*/) {

 

var gr = new GlideRecord('incident_task');

gr.addQuery('active','true');

gr.addQuery('incident',current.sys_id);

gr.query();

if (gr.next()) {

   gs.addInfoMessage('This Incident cannot be resolved as there is or are active child Incident Tasks. Please close them first');

current.incident_state = previous.incident_state; 

   current.state = previous.state;

   current.setAbortAction(true);

   gs.setRedirect(current);

}

 

})(current, previous);

View solution in original post

14 REPLIES 14

@Chaitanya ILCR , yes tried- showing error message but getting error as 'Invaild Update' and state is changing to resolved not preventing

Hi @Kusuma Sai ,

that means it's working

just reload the page the state will show the previous value

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

No not working, State is changing to resolved 

prudhviraj1
Tera Guru

Hi @Kusuma Sai ,

 

Try to use Before Update BR only.

(function executeRule(current, previous /*null when async*/) {

 

var gr = new GlideRecord('incident_task');

gr.addQuery('active','true');

gr.addQuery('incident',current.sys_id);

gr.query();

if (gr.next()) {

   gs.addInfoMessage('This Incident cannot be resolved as there is or are active child Incident Tasks. Please close them first');

current.incident_state = previous.incident_state; 

   current.state = previous.state;

   current.setAbortAction(true);

   gs.setRedirect(current);

}

 

})(current, previous);

Chaitanya ILCR
Mega Patron

HI @Kusuma Sai ,

My bad 

it was supposed to be Or condition for incident and parent fields

 

(function executeRule(current, previous /*null when async*/ ) {

    var taskGR = new GlideRecord('incident_task');
    taskGR.addEncodedQuery('active=true^parent=' + current.sys_id + '^ORincident=' + current.sys_id);
    taskGR.query();

    if (taskGR.hasNext()) {
        gs.addErrorMessage('Cannot close the incident while active child tasks exist.');
        current.setAbortAction(true);
    }

})(current, previous);

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya