Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Don't close incidents when incident tasks are open

riaz_mansuri
Kilo Guru

Hi

I would like to create a rule that if an Incident has any Open (Incident) Tasks the Incident cannot be closed.

Not all Incidents will have tasks.

Any help?

Thanks

Riaz

1 ACCEPTED SOLUTION

Hi Riaz,



Please add filter condition in BR as below:


find_real_file.png


and in code do the gliding on incident_task table rather then incident as below and then try:


find_real_file.png



Thanks,


Anjali


View solution in original post

12 REPLIES 12

Sanjeev Kumar1
Kilo Sage

Hi Riaz,



Create a Business Rule on incident table.


to implement this.


I think it will help you If you are looking for some code let me know.


Hi Sanjeev,



Thanks - Yes some code would be good please. I assume maybe a generic piece of code.



Thanks


Riaz


Hi Riaz,



Check with the below code once



Table:Incident


business rule type: before update


Filter condition : State changes to closed





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




// Add your code here


if(current.state=="3"){   //here 3 is the value of closed state


var inctask=new GlideRecord('incident_task');


inctask.addQuery('parent',current.sys_id);


inctask.query();


while(inctask.next()){


if(inctask.state!="3"){//here 3 is the value of closed state


gs.addErrorMessage("Incident task is not closed");


current.setAbortAction(true);


}


}


}




})(current, previous);


anjalichoudhary
Kilo Guru

Hi Riaz,



You can try creating a Business Rule as below:



Name: Prevent Closure if Child Task is Active


Type: "Before Update" Business Rule


Table: Incident


Description: Prevents closing a task if any of the task's child tasks are still active.


Script:


var gr = new GlideRecord('incident');


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


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


gr.query();


while (gr.next())


{


current.setAbortAction(true);


}



If the reply was informational, please like, mark as helpful or mark as correct!!



Thanks,


Anjali