Task should be closed before being able to close Case

Rob Sestito
Mega Sage

Hello everyone,

We use Tasks (child) to task a Case (parent) out to certain employees. We are having an issue, where the Parent Cases are able to be closed, while the Child Task is still open. I thought there would be an OOB BR to not allow this (should there be?) From what I read, looks like there should be a 'wait for condition' kind of workflow BR to handle this, but does not seem to be the case.

Anyone able to explain/show me how I can accomplish this. Tasks (child) should be closed first before the Case (parent) is able to be closed.

Thanks to anyone in advance,

-Rob

1 ACCEPTED SOLUTION

When to run should be before. We want to catch the user before they save the record as closed. No need to set the Actions tab since we are handling this in our script. Here are the details for the business rule:



Name: Abort for open Child Tasks


Table: Case [hr_case]


Advanced: true


Condition: current.state.changesTo(3)


Script:


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


      var recObj = new GlideRecord('hr_task');


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


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


      recObj.query();


      if (recObj.hasNext()) {


              gs.addErrorMessage('Cannot close with open Child Tasks');


              current.setAbortAction(true);


      }


})(current, previous);



I am guessing that the closed state has a value of 3. You can change it to whatever the appropriate closed state is.


View solution in original post

10 REPLIES 10

Thank you so much Chris!


And yes you are correct - the child table is hr_task.


I will give this some testing to this and see if I can get it to work properly.



So in trying to understand the 'story' I am trying to paint. The "when to run" tab - would be set for   'after' 'update'? (and would I need to set any filter conditions?)


Then then "Actions" tab - Set field values would be?



Are you able to help with setting those two tab options for this? I am trying to figure out what they should be set to, but getting lost in my thinking process for it.



I appreciate your time and help with this!


-Rob


When to run should be before. We want to catch the user before they save the record as closed. No need to set the Actions tab since we are handling this in our script. Here are the details for the business rule:



Name: Abort for open Child Tasks


Table: Case [hr_case]


Advanced: true


Condition: current.state.changesTo(3)


Script:


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


      var recObj = new GlideRecord('hr_task');


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


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


      recObj.query();


      if (recObj.hasNext()) {


              gs.addErrorMessage('Cannot close with open Child Tasks');


              current.setAbortAction(true);


      }


})(current, previous);



I am guessing that the closed state has a value of 3. You can change it to whatever the appropriate closed state is.


Okay yes - that makes sense. Not sure why I was thinking it would run 'after'..


I am going to go through and see if I can get this working with some testing.



Thank you so much for your input! Once I get it to work (hopefully), I will let you know.



-Rob


Hey Chris,



It looks like it was pretty close - it shows the error message stating a child task is still open (which is true) - however it still allows/ pushes parent case state to close complete - with the child task remaining open (screen shot provided).



However, I noticed something else too - I went to the child task, put that in a closed complete state. Updated - system puts me back to the parent case, and that now shows 'awaiting acceptance" state. So that is a bit interesting.. It looks like it is doing it, just in a very odd way. When I go to my list view, the case I am using for testing, is under the list of Closed Cases, even though the state shows Awaiting Acceptance (attached screen shot for this too).



And idea(s) as to why this may be?



Thanks,


-Rob


It may be that the order of the Business Rule occurs after one that sets the active flag. You may want to check other before business rules to see when they are running and change the order of the one you wrote to be earlier. We want it to run first since we are aborting the save entirely. We do not want other things to occur.