REQUEST A DEMO

How To: Close a case when all of its subcases are closed

 

I got a question today about how to close a case when all of its subcases are closed.

 

You could certainly add code to your application (such as the Clarify Client or Dovetail Agent), but to me, this sounds like more workflow automation, and we can do that with business rules. Plus, if you use multiple client applications (lets say the Clarify Client and Dovetail Mobile) – you don’t want to have to customize each of those apps.

 

To accomplish this task, we’ll create a business rule that fires when a subcase is closed. If all of its sibling subcases are also closed, then we can close the case.

 

First wrinkle: How do we know when all of a subcase’s siblings are also closed?

 

One way to do it is to look at all of the subcase conditions, and make sure none of them are Open. To do this, we’ll need a custom rule property.

Rule Property

 

Create a custom rule property that lists all of the conditions for the subcases for the case. Normally a rule property resolves to one value. But if a rule property resolves to multiple, then Dovetail Rulemanager will simply create a comma-separated list of all of the values. Don’t worry if this doesn’t make sense  – I’ll illustrate it with a specific example in a bit.

 

Here’s what my custom rule property looks like:

 

Prop

 

Notice that we traverse from the subcase up to the case, then from the case to the subcases. Recall that there can be many subcases for one case. Then we get the condition for each case.

 

When Dovetail Rulemanager evaluates this property, we’ll get a list of conditions. Rulemanager’s log file gives up the details:

DEBUG FChoice.RuleManager.StandardPropertyTokenExpansionService –
Property “Conditions of Sibling Subcases” using “subcase2case:case2subcase:subc_state2condition:title” expands to “Closed,Open,Closed,Closed”

 

So we can see that we have 3 closed subcases and 1 open subcase.

Business Rule

 

Next, we setup a business rule to fire when a subcase is closed, and only fire when there are no open subcases.

 

Title: close subcase’s parent case

Description: Close parent case when all subcases are closed

Object Type: subcase

Start Event: Close Task

Cancel Event: None

Condition: Conditions of Sibling Subcases does not contain Open

Action Title: Close case

Action Type: Command Line

Message: C:repopowershellCloseCase.bat [Parent ID]

Start Action: 0 seconds from event creation using Elapsed Time

Repeat: None

Scripts

 

Notice that the action for this rule is to call a command line script. In my test, I call the CloseCase.bat script, which is simply a wrapper around a Powershell script named CloseCase.ps1. This Powershell script calls the CloseCase API within the Dovetail SDK. Pretty simple.

 

I’ve shared all my Powershell scripts up on Github at: https://github.com/gsherman/powershell

 

The specific ones I used in this scenario are CloseCase.bat and CloseCase.ps1.

Test it

 

I have a case that has 4 subcases. 3 closed, 1 open. I closed the last one, and I can see the rule get fired and that it calls my script which closes the case.

 

The case history shows just what I expect:

 

History

 

And here’s a snippet from the Rulemanager log showing exactly what happened:

 

INFO  FChoice.RuleManager.ScheduledApplicationEvent - Executing ScheduledApplicationEvent.
DEBUG FChoice.RuleManager.Condition - Evaluating condition 268436070: Property: "Conditions of Sibling Subcases", Right operand: "Open", Operator: "DoesNotContain", Type: "String"
DEBUG FChoice.RuleManager.PropertyRepository - Item "Conditions of Sibling Subcases" was retrieved from the Repository cache.
DEBUG FChoice.RuleManager.QueryBuilder - Path "subcase2case:case2subcase:subc_state2condition:title" expands to SQL command "SELECT T3.objid, T3.TITLE FROM table_subcase T0, table_case T1, table_subcase T2, table_condition T3 WHERE T0.objid = {0} AND T0.subcase2case = T1.objid AND T1.objid = T2.subcase2case AND T2.subc_state2condition = T3.objid ORDER BY T3.objid DESC"
DEBUG FChoice.RuleManager.StandardPropertyTokenExpansionService - Property "Conditions of Sibling Subcases" using "subcase2case:case2subcase:subc_state2condition:title" expands to "Closed,Closed,Closed,Closed"
DEBUG FChoice.RuleManager.ConditionOperators.DoesNotContain - Forcing both operands to be of type "String"
DEBUG FChoice.RuleManager.Condition - Condition 268436070 evaluated to True
DEBUG FChoice.RuleManager.PropertyRepository - Item "Parent ID" was retrieved from the Repository cache.
DEBUG FChoice.RuleManager.QueryBuilder - Path "subcase2case:id_number" expands to SQL command "SELECT T1.objid, T1.ID_NUMBER FROM table_subcase T0, table_case T1 WHERE T0.objid = {0} AND T0.subcase2case = T1.objid ORDER BY T1.objid DESC"
DEBUG FChoice.RuleManager.StandardPropertyTokenExpansionService - Property "Parent ID" using "subcase2case:id_number" expands to "29"
DEBUG FChoice.RuleManager.ProcessExecutor - Command to be executed: "C:repopowershellCloseCase.bat  29"
DEBUG FChoice.RuleManager.ProcessExecutor - Starting process: "C:repopowershellCloseCase.bat" with arguments "29" in directory "C:appsDovetail SoftwareRule Manager"

 

And that’s it. About 10 minutes of work. Pretty simple.

 

Hope you find this useful.

 

Rock on.