Importing parent/child relationships

The case importer allows you to import parent/child case relationships and gives you two ways to do this.

There are 2 approaches:

1. Importing new parent and child cases at the same time

Important!

Please make sure you have a parent_type column in your import! This is required along with the parent_id field.

You will need two Excel files, one for parent cases and one for child cases.

Your parent case file will need:

Your child case file will need:

  • A column to uniquely identify the child cases (external_id)

  • A column to identify the parent case (parent_external_id)

  • A column to identify the parent case type (parent_type)

Example parent excel file (case type is father)

external_id

name

external_id

name

A1

Tom

A2

Joe

A3

Bob

Example child excel file: 

external_id

name

parent_external_id

parent_type

external_id

name

parent_external_id

parent_type

child1

Tom's Son

A1

father

child2

Tom's Daughter

A1

father

child3

Bob's Son

A3

father

  1. Import the parent case file (if needed).  Make sure you match external_id to the External ID when identifying how to identify cases. 

 

  1. Import the child case file.  Make sure you match external_id to the External ID when identifying how to identify cases. 

     

  2. When mapping columns for the child case file, make sure you map parent_external_id and parent_type columns. 

2. Importing parent and child cases separately

Important!

Please make sure you have a parent_type column in your import! This is required along with the parent_id field.

When you would want this approach:

  • If your parent cases are already in the system

  • You don't want to deal with external_id's on your cases

Warning: Depending on how unique the rest of your data is, it can be hard to correctly match up the parent cases imported with those exported.  Be very careful with this step, as getting it wrong can cost you a lot of time and effort fixing it.  Using external_id's (or making sure you have at least one completely unique identifier on your data) would be a good way to avoid this potential hassle.

 

If you are importing both parent and child cases separately, you would need:

  1. Import parent cases excel file (https://dimagi.atlassian.net/wiki/x/TAjKfw )

  2. Export parent's case_id

    1. Select the 'Data' tab from the options at the top of the screen, choose 'Export Cases', filter appropriate users and download your parent cases.

  3. Create Child case excel file:

a. Your Excel spreadsheet should be broken down into columns matching different case properties in your application. 

b. Match your parent's case_id to your child case excel file (see warning above!) 

  • Note: if you have downloaded a case export and are using those fields as your template for importing, the case export will show the field indices.parentcasetype (where "parentcasetype" is the case type of your parent case). Do not use indicies.parentcasetype, instead, replace this text to say parent_id.

  • Match your parent's case type using a column called "parent_type" (this is required).

Example child case excel file:

ID

name

parent_id

parent_type

owner_id

1

Child One

dbd248b6a4744652b9535ad

example_type

f1b782cf397106625955f69

2

Child Two

e20157f404704fbfaef4b21

example_type

f1b782cf397106625955f69

  4. Import child cases excel file (follow https://dimagi.atlassian.net/wiki/x/TAjKfw).

First, map on case id to some column. Then, click 'Create new records if there is no matching case'

Then, map the parent id and parent type columns so the relationship is created.

  • Click "Create a new property instead"

  • Enter "parent_id" as shown in the image below

  • Repeat for "parent_type"

Warning: If a parent_id is provided and no case with the provided case ID exists, the row gets ignored by the case importer without any warning messages. If you neglect to add "parent_type", the import will fail.