MSForms for Self-Registration

MS Forms with the help of Power Automate can be used for submitting forms that integrate with CommCare to create new cases on the system! 

Overview

This is a powerful feature that allows for self-registration workflows on CommCare wherein beneficiaries can directly fill out an MS form on any device. Once submitted, this will create a case in CommCare which can then be used for case management workflows. 

For an introduction into using PowerAutomate, please visit Power Automate Integration Set-Up

Step 1: Create your registration form

Create a simple registration form that captures details of the beneficiary. Ensure that the fields are case properties on the CommCare app where this data needs to flow. 

Step 2: Create an automated cloud flow on MS Power Automate

Once the flow is created, add the following steps.

  • The first step is referencing an MS form submission by choosing the following trigger. Select the form created and save.

 

  • The second step is to add an action called “get response details” and reference the response ID

 

  • The third step is to set up an action for HTTP as below.

 

  • 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.

 

  • 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 app}/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. 

In the second section, please paste the raw XML of the case created in CommCare. The pertinent values can then be edited. Copy the XML to clipboard and paste it into the body section of the HTTP operation in Power Automate.

 

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).

The first field in the form is <name> that needs to be pulled from the MS form submission. Delete all the values in between the brackets and drag the relevant field from the screen. This section is saving the individual form fields. 

The next section is creating the case ID for the case. 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. 

The next section is creating the case and updating case properties. Again, repeat the process of updating the case properties with the MS form fields as shown below.

 

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 complete, the flow will look like this: 

Step 3: Submit MS form and check CommCare for case creation

Once the flow is set up, submit a form via the MS form created. If the flow is set up correctly, it would trigger instantly and within a few seconds, the new case will be visible on CommCare. 

If the integration fails, there will be an error response as well which can be investigated and code fixed accordingly.