This feature (Automatically Close Cases) is only available to CommCare users with a Pro Plan or higher. For more details, see the CommCare Software Plan page.

 

Overview

This feature allows users with Edit Data access (see CommCareHQ Web Users) to configure updates to cases, including the ability to close cases. Without this feature the only ways to close cases are by filling out a form which closes a case, finding the case in the Case List and manually using the Close Case button, or by using the Importing Cases Using Excel tool.

Here are some examples of when this is useful:

Cases are closed by creating rules

The basic process of defining a rule is:

  1. Define all of the criteria for the cases you want to match. 

  2. Choose all of the actions to apply to the cases that match the criteria.

Rule List

Navigating to Data -> Automatically Close Cases you will see a list of all rules for the project along with the last time the rule has run to completion. If "Last Run" is not updated, it means that the rule has not yet run or did not run to completion on its last run. The completion could not have succeeded due to exceeding of the maximum number of automatic updates per day (10,000), due to exceeding the max run time (24 hours), or that there was an error during the run.

 

Rules

Creating a New Rule

You can create a rule by navigating to Data -> Automatically Close Cases: 

For example, imagine that you want to close any "person" cases which have not been updated in a year. You want to do this to reduce the case load on the users' phones and to keep the reports accurate.

The first step is to click on Add Automatic Close Rule and fill out the basic information by giving the rule a name you can use to remember what it's for:

Next, add your filter criteria which define the cases that the rule will apply to. The criteria pictured below say to match all cases with case type "person" that have not been modified in 365 days:

And lastly, specify the actions that will be applied to the cases that match these criteria. These actions say to close the case and update case property "close_reason", setting it to the value "automatic".

Case Filter Criteria

The following filter criteria are available for matching cases:

NB: It is possible to reference parent/master case properties in any of the case property filters. The syntax follows the convention of "parent/<case_property>" or "host/<case_property>". Possible use case: Close the growth monitoring case when the parent (i.e person case) turns 6.5 years old. 

Actions

The following actions can be performed on cases which match the filter criteria:

Running a Rule

Rules run automatically every day at Midnight GMT. You cannot choose when a rule is run.

Managing Rules

You can update, delete, or deactivate a rule at anytime from the list of rules.

Case References

In addition to the dynamic case properties created by your app(s), you can reference the following case properties in automatic update rule criteria:

Case PropertyDescription
nameThe case's name
owner_idThe system identifier for the case's owner
opened_onThe timestamp that the case was opened
opened_byThe system identifier for the case's opener
modified_onThe timestamp that the case was last modified on mobile
server_modified_onThe timestamp that the case was last modified on the server
external_idAn optional external id your app may assign to the case

Parent cases may also be referenced in the automatic update rule criteria by prefixing the property name with "parent/". So, for example, parent/name references the parent case's name.

Reporting and Case Actions

The case close action shows up the case history as a form submission. You can view the form that closed the case by looking in the Submit History report or the Manage Forms tool. The form will also show up in the Case History of any cases closed by a rule. In the case history for the form name will show up as "Unknown" and the user as "system":

Reversing a Rule

If a rule ran and closed cases and you want to undo that action, you should go to Manage Forms or Submit History report, locate the form submission that closed the cases, and archive it. This will restore the case to its prior status. For more information on archiving forms, please see Archive Forms.

To find the forms you will want to use the following filters:

You can add the filter options in the following order:

  1. Choose Unknown Users
  2. Select Advanced Options
  3. Select Unknown Forms
  4. Choose Unknown Form Name "http://commcarehq.org/hq_case_update_rule