[Power Automate] Child Cases Flow Configuration
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
member_id
Relation_to_Head: Used for:
n0:relation_to_head
relation_to_head
parent_case_id: Used for:
n0:parent element in the n0:index section
case_id: Used for:
n0:case attribute case_id
Outer XML_Data_Mapping: Maps data for each parent case block, transforming it into XML format. This includes the parent case update, XML header and XML footer.
The rest of the flow uses logic and conditions to iterate and increment node values, parse JSON data and create structured XML body for submission to CommCare.
Parent Case Update Block
Element | Attribute | Description | Value/Example |
---|---|---|---|
|
| Represents a case element in CommCare |
|
|
| Namespace for CommCare case transaction |
|
|
| Unique identifier for the parent case |
|
|
| Date and time when the case was last modified |
|
|
| User ID responsible for the case creation or update |
|
These values are dynamically filled into the XML structure using the placeholders @{body('Parse_JSON')?['parent_case_id']}
where parent_case_id corresponds to the column from the SQL database.
parent_case_id
Used for:
n3:case attribute case_id
XML Footer Block
Element | Attribute | Description | Value/Example |
---|---|---|---|
|
| Namespace for form metadata |
|
|
| ID of the device 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 |
|
|
| Application version used for the form submission |
|
|
| Time drift indicator |
|
XML Header Block
Element | Attribute | Description | Value/Example |
---|---|---|---|
|
| Namespace for CommCare XForms |
|
|
| Namespace for the form designer |
|
|
| User interface version |
|
|
| Version of the form |
|
|
| Name of the form |
|
Final XML for Submission: Combines the XML header, case data, and footer into a final XML string for submission.
This action concatenates the value of each of the above XML blocks to create the final XML body for submission to CommCare.
Form Submission to CommCare: Submits the final XML data to CommCare via an HTTP POST request, including Authorization headers.
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. Ensure that the xmlstring is reset after the submission.