Power Automate for Data Migration
For advanced users: Learn how to use Power Automate to migrate data from other platforms into CommCare with example scripts, detailed steps, and troubleshooting tips.
Parent Cases
This flow facilitates the migration of Parent Cases from the SQL database to CommCare. The flow is integrated within Power Automate and utilizes multiple components to ensure the accurate transfer and transformation of data.
Flow Components
Trigger: The flow is manually triggered, allowing users to start the process on demand. This trigger is set up as a button in Power Automate, providing flexibility in scheduling migrations.
The following actions are part of the flow:
Get Rows from SQL Database:
Operation: This action retrieves rows from the SQL database, specifically targeting the [dbo].[households] table. It extracts all necessary data fields required for migration.
Connection: The connection is made using a predefined SQL Server connector.
XML Creation Loop:
This loop iterates over each row obtained from the SQL database. For each row, it performs the following actions:
Individual Row Transformation:
Update XML Action: Converts the data into an XML format suitable for CommCare. The XML structure includes essential elements like household_id, location, and case_id. The transformation ensures that each row is correctly formatted and ready for submission.
Paste the Raw XML copied previously for the household registration form submission in the input of the Compose action.
Here's a table format for the XML structure, breaking down each element and its details:
Element | Attribute | Description | Value/Example |
|---|---|---|---|
|
| Namespace for CommCare XForms |
|
|
| Namespace for the form designer |
|
|
| User interface version |
|
|
| Form version |
|
|
| Name of the form |
|
|
| Unique identifier for the household |
|
|
| Location information for the household |
|
|
| Namespace for CommCare case transaction |
|
|
| Unique identifier for the case |
|
|
| Date and time when the case was last modified |
|
|
| User ID responsible for the case creation or update |
|
|
| Section defining the creation of a new case |
|
|
| Name of the case |
|
|
| ID of the case owner |
|
|
| Type of the case |
|
|
| Section including updates to the case |
|
|
| Unique identifier for the household (updated) |
|
|
| Location information (updated) |
|
|
| Namespace for form metadata |
|
|
| Device ID used for form submission |
|
|
| Start time of form entry |
|
|
| End time of form entry |
|
|
| Username of the person submitting the form |
|
|
| User ID associated with the form submission |
|
|
| Unique identifier for the form instance |
|
|
| Namespace for application version |
|
|
| Formplayer version used |
|
|
| Time drift indicator |
|
This table outlines each XML element, its attributes, descriptions, and example values. This structured format helps in understanding the composition and purpose of each part of the XML.
These values are dynamically filled into the XML structure using the placeholders @{items('Individual_Row_Transformation')?['FieldName']} where FieldName corresponds to the columns from the SQL database.
Household_ID
Used for:
household_id
n0:case_name
n0:household_id
Location
Used for:
location
n0:location
case_id
Used for:
n0:case attribute case_id
Form Submission to CommCare:
This action submits the XML data to CommCare via an HTTP POST request. The request includes an Authorization key and a predefined URI for the CommCare receiver endpoint. This ensures the data is securely transferred and integrated into the CommCare system.
Child Cases
This flow automates the process of migrating child case data from an SQL database to CommCare. It handles the extraction, transformation, and submission of data in the correct XML format, ensuring that all child cases are accurately represented and linked to their parent cases.
Flow Components
Trigger: The flow is manually triggered, allowing users to start the process on demand.
The following actions are part of the flow:
Initialization and Variable Handling: Initializes and manages variables like prefixCounter, prefixCounter_parent, and combinedxmlstring for counting and concatenating XML data blocks.
Get Data from SQL and Retrieve Unique Parent Case IDs:
Get Rows from SQL Database: Retrieves rows from the [dbo].[household_members] table in the SQL database.
Select_Parent_Case_IDs: Extracts the parent_case_id from the retrieved SQL rows.
List_Unique_Parent_Case_IDs: Generates a unique list of parent case IDs.
Individual XML Generation for Submission: Iterates over each unique parent case ID and performs the following actions:
Filter_array: Filters rows based on matching parent_case_id.
Individual Case XML Blocks for Child Case: Processes each individual child case related to the parent case.
Add Individual Fields from SQL Rows: Adds specific fields like case_id, Name, Age, Gender, etc., to the XML.
Append to string variable: Appends the formatted XML string for each case.
Paste the Raw XML copied previously for the household_members registration form submission in the input of the Compose action. Select only the <household_member_details> block.
Here's a table format for the XML structure, breaking down each element and its details:
Element | Attribute | Description | Value/Example |
|---|---|---|---|
|
| Root element for household member details |
|
|
| Namespace for CommCare case transaction |
|
|
| Unique identifier for the household member case |
|
|
| Date and time when the case was last modified |
|
|
| User ID responsible for the case creation or update |
|
|
| Section defining the creation of a new household member case |
|
|
| Name of the household member case |
|
|
| ID of the case owner |
|
|
| Type of the case |
|
|
| Section including updates to the household member case |
|
|
| Age of the household member |
|
|
| Gender of the household member |
|
|
| Unique identifier for the household member |
|
|
| Relation of the household member to the head of the household |
|
|
| Section defining the index relationship |
|
|
| Type of the parent case |
|
|
| Parent case ID |
|
|
| Repeated identifier for the household member |
|
|
| Name of the household member |
|
|
| Age of the household member |
|
|
| Gender of the household member |
|
|
| Relation of the household member to the head of the household |
|
This table outlines each XML element, its attributes, descriptions, and example values. This structured format helps in understanding the composition and purpose of each part of the XML.
These values are dynamically filled into the XML structure using the placeholders @{items('Individual_Row_Transformation')?['FieldName']} where FieldName corresponds to the columns from the SQL database.
Name: Used for:
n0:case_name
name
Age: Used for:
n0:age
age
Gender: Used for:
n0:gender
gender
Member_ID: Used for:
n0:member_id