
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 08:09 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 09:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 08:25 AM
you can write a before update BR on Parent table, which will check for the child task based on the relationship.
Check for any of the child status is not closed and abort action.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 08:25 AM
I am guessing that the Child task relates to the parent through the Parent [parent] field. For this example I will use case_task for the child, and case for the parent (feel free to change to the correct tables).
Write a before business rule with the conditions of when the record becomes closed. Here is the script that looks for open case tasks:
(function executeRule(current, previous /*null when async*/) {
var recObj = new GlideRecord('case_task');
recObj.addQuery('parent', current.sys_id);
recObj.addQuery('active', 'true');
recObj.query();
if (recObj.hasNext()) {
gs.error('Cannot close with open Child Tasks');
current.setAbortAction(true);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 08:49 AM
Thanks for this Chris!
Do you know, would it be safe for me to say that when creating this BR - the table should be set to the "case/parent" table for this BR? Screen shot to try and help explain.
I am still fairly new to the whole SN/JavaScript - So I am trying to grasp the best understanding that I can.
Thank you so much with your help so far!
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 09:10 AM
Yes, the table should be the parent table. In your situation it is the Case [hr_case] table. Since I do not have HR Case Management installed, it is difficult for me to validate my code on my personal development instance. My guess is that the child table is hr_task, correct? I adjusted the script so that it will run on the hr_case table:
(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);
What I am doing is running a GlideRecord Query against the hr_task table.
I look for those records that have a parent of the current record, and are active.
After running the query, I check to see if I have any records found (recObj.hasNext())
If I do, then I add the Error Message at the top and abort saving the record.