Power Automate Integration Set-Up
This page provides step-by-step instructions for setting up your PowerAutomate connection.
Overview
CommCare has a fluid integration with Power Automate, enhancing workflow efficiency and automation capabilities. This integration enables users to streamline processes, transfer data effortlessly, customize workflows, and increase productivity. With Power Automate, automated workflows can be created to connect CommCare with various applications and services, ensuring smooth information exchange and personalized automation solutions. Automating repetitive tasks allows users to focus on strategic initiatives, boosting overall productivity.
The instructions below take you through the process of setting up thsi integration.
Setup: Begin by following the detailed setup instructions provided below to establish the connection between CommCare and Power Automate.
Configuration: Customize workflows within Power Automate to interact with CommCare data, trigger actions, and automate processes based on predefined conditions.
Execution: Once configured, watch as your automated workflows seamlessly operate, saving time and effort while ensuring data accuracy and consistency.
CommCare Setup
Below are instructions for how to set up your Power Automate Integration. See this video https://www.loom.com/share/d270546540c5479485a8aa928692c047?sid=538c5c8b-6478-4b73-a3d2-0bed7eb3d3ed along with the instructions below to understand how it works!
Step 1
Create an application on CommCare with a case management workflow. Be sure to map all case properties in the registration and follow-up forms.
Step 2
Submit a form for registration and follow up. Repeat the process for as many forms you need to setup this workflow for. Navigate to the Case List report and look at the Case History section and copy the raw XML of each submission for use later.
Survey Tool Setup
Step 1
Create surveys on external survey tools like MS Forms, Google Forms, Jotform or more with the questions that you built within the CommCare app. Please do any necessary due diligence before choosing the survey tool.
You can read more about specific survey tools below:
https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2300938533
https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143954145
Step 2
Ensure that all the fields you need mapped to CommCare are included. In the case of followup forms, ensure that a “case id” question is always included in the survey. Test a few submissions (currently not connected to CommCare) to ensure the data is formatted the way you need it.
Step 3
Save the URL of the form for use later. Different survey tools have different ways to get the form link.
On MS Forms:
On Google Forms:
On Jotform:
Step 4
Create a pre-filled survey link where the case id question can be appended to the URL. We will need this to populate case ids when the link is shared with respondents for updating existing case data on CommCare.
In current testing, this can be achieved on Google Forms and Jotform. There may be other tools that allow appending the survey URL as well. Please feel free to test on your own.
On Google Forms:
On Jotform:
Step 5
After selecting prefill, fill the case id question with any arbitrary value. Note that we are only using the URL for generating a structured link from CommCare later.
On CommCare, the following approaches can be explored for sending the form links:
For new cases: Share the survey link generated above to respondents either manually (outside of CommCare) or via messaging workflows within CommCare. These could be SMS/emails that contain the survey link which the respondent can navigate to and submit responses.
For updating cases: Use the pre-filled URL and add the case id of the respondents to the end and use the same options above for sharing with the respondents.
See here for setting up messaging workflows on CommCare.
Known Limitations
A known limitation of MS forms is the inability to append case ids to survey links so it cannot be used for any case update workflows. It can be used for case creation workflows.
A known limitation of Google forms is the inability to hide/hardcode the case id value which means that users can still make changes to it. You are encouraged to use relevant warning messages to ensure the value is not changed.
Setting up Google Forms integration requires additional steps as Power Automate does not have an existing connector for Google Forms. See https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2392424567 for detailed instructions.
Power Automate Setup
Step 1
Create an automated flow on Power Automate to capture survey responses and submit them back to CommCare. Note that the flow steps may vary slightly depending on which survey tool is chosen.
Understanding the flow structure:
The first step in any flow is essentially getting survey responses. This may look different for the three tools we have tested depending on the kind of workflow required to get the responses. See below for specifics:
Step 2
Set up the HTTP step using CommCare’s form submission API.
Populate the HTTP code. The easiest way to do this is to create a case on CommCare, navigate to the case list report, go to case history and pull up the raw XML file of the submission that created the case or updated the case.
Here’s a breakdown of all the sections.
In the first section, please choose the following fields
Method: POST
URI: https://www.commcarehq.org/a/{name of project space}/receiver/{APP ID}/
APP ID can be accessed from the URL when the app is being edited. This value is static and should be saved beforehand.
Here’s a breakdown of the code in the Body section of the HTTP operation.
Everything remains the same for the metadata (ie. the xmlns and app attributes right up to the form name (line 3).
Section 1: The first section in the body after the namespaces contains the individual responses to the form. Replace the values from the pasted XML with the responses listed in Power Automate.
Section 2: Starting at node 0 (<n0:…) will either show case creation or case update blocks. Again, remove the existing values and use the GUID() expression for the ID field and the utcNow() for creating new values. The user_id value remains the same. For case updates, use the case id value from the form submission as well.
Section 3: Starting at node 1 (<n1:…) will be metadata where timeStart, timeEnd and instanceID will require updates.
timeStart: utcNow()
timeEnd: utcNow()
instanceID: guid()
Step 3
Finally, click on Show Advanced options and choose either Basic/API Key for authentication.
For basic authentication choose Basic and add email address/password.
For API key authentication, add header key and value like below:
Header Key: Authorization
Header Value: ApiKey [email address]:[API key from CommCare]
Ensure that the Authentication type at the bottom is selected as None.
Once the the above is setup, test survey links for new respondents as well as existing ones (with cases created on CommCare already). If the workflow is setup correctly, form submissions will show up in CommCare and all case data will be created/updated. You can check the Case List Report to check for updates.