Prevent Incident Resolution When Tasks Are Still Open

gaf627
Tera Expert

We have a need to provide the ability to create Incident Tasks for our Applications Team, as they often divide up work when addressing an incident.     As discussed in many other incident task discussions, we've taken the advice given and extended the Task Table to create Incident Tasks.   The applications team can now create Incident Tasks without issue; however, they are Resolving Incidents without closing their tasks.     We would like to do a check to prevent this by displaying a message when they set the Incident state to Resolved if there are Open Tasks.       Initially, we attempted to do this with a Business Rule, without scripting and just using a filter in the Business Rule.   It appears this would work, if I was able to set When To Run with a Filter Condition on Incident when State changes to Resolved and   select the Incident Task table and filter on Active or State = Open.     Is this possible to execute a Business Rule on the Incident table and filter on both the Incident table and Incident Task table by dot walking?   For some reason, I am unable to select the Incident Task table and fields.   Thanks!

13 REPLIES 13

What am I missing - not having any luck with the script.



Business Rule:


Table: Incident_Task


When to Run: Before and Update


Conditions: current.incident_state == IncidentState.RESOLVED



function onBefore(current, previous) {



  var target = new GlideRecord('incident_task');


  // table name for your Incident task


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


    //this is   the field which will link Incident to Incident task


  //search for open Incident tasks


  target.addQuery('state', 1).addOrCondition('state', 2).addOrCondition('state', -5);


  // check for open Incident task - add/edit states integer values as appropriate


  target.query();



  if(target.hasNext()){


  if ((current.incident_state == 6) || (incident.problem_state == 7)){  


  gs.addInfoMessage("You have open tasks which must be completed before this record can be closed");


  current.setAbortAction(true);


  }


  }


}



The End Result I am looking for is for a Alert message and for the Incident not to Resolve unless all Incident Task are Closed.


You can look at replacing the below line with a query to check only for 'active=true' incident tasks.


target.addQuery('state', 1).addOrCondition('state', 2).addOrCondition('state', -5);



Also, I think it makes sense to hide the button if the incident has some related tasks that are active. Why do we need to show the user a button if is not actionable? You can add a info message on top of the form if the incident has tasks so that people are not confused on the unavailability of the button. Hope that helped!


Steven Young
Tera Guru

you could edit the UI Action (button) to run a query of the incident task table and if there are some open, then alert the user this incident cannot be closed until all children have been resolved.


shloke04
Kilo Patron

Hi,



To prevent the Parent incident Record being Closed if the Child Records are still open, you can write a Before Update Business Rule on The Incident Table



Script:



Give the Filter Conditions as "State ChangesTo Resolved"



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



  // Add your code here


  var gr = new GlideRecord('incident_task');


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


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


  gr.query();


  if (gr.next()) {


  gs.addInfoMessage(('Please Close all the Incident Tasks before Resolving the Incident'));


  current.state = previous.state;


  current.setAbortAction(true);


  }



})(current, previous);



find_real_file.png


find_real_file.png



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

I used this script and I see the addInfoMessage indicating the GlideRecord is testing true for an open incident_task but the state field remains Resolved. Is there a way to reload the form so that the State field reflects the previous.state which for us is Pending Tasks? I have read there is a bug that prevents gs.setRedirect(current.getLink(true));     when using   current.setAbortAction(true);. Is this what is preventing the page reload if so I will propmpt users to manually reload page with a message.