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
Kilo Patron

Hi @Kusuma Sai ,

update your BR as below

ChaitanyaILCR_0-1749815654561.png

and replace your BR script with 

ChaitanyaILCR_1-1749815712903.png

 

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

    // Add your code here
    var taskGR = new GlideRecord('incident_task');
    taskGR.addQuery('parent', current.sys_id);
    taskGR.addQuery('incident', current.sys_id);
    taskGR.addActiveQuery();
    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

Hi @Chaitanya ILCR , I have tried the same, but not helping.

Hi @Kusuma Sai ,

it should work

did you copy paste the entire script and check?

replace the entire script in the BR with below
I have added try catch if in case of any issue it'll be displayed in the form

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

    try {
        var taskGR = new GlideRecord('incident_task');
        taskGR.addQuery('parent', current.sys_id);
        taskGR.addQuery('incident', current.sys_id);
        taskGR.addActiveQuery();
        taskGR.query();

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

})(current, previous);

and also please share in details of what's not working if it's working if doesn't work

 

 

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

Regards,
Chaitanya

Can you please suggest

what i have added here ? Incident Task > Incident or Incident Task Parent ?

What I have to do visible "Incident Task Parent"

KusumaSai_0-1749818303321.png

 



Hi @Kusuma Sai 

Add both that's should be fine

did you try the script I have shared ?
I have included the both parent and incident  fields in the script

 

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

 

Regards,

Chaitanya