...
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Step 1
Create a form on Google forms based on the app structure built in CommCare.
...
Step 2
Navigate to to Script Editor by clicking on the three dots next to Send on the top right corner.
...
Step 3
Create a new script and name it “Retrieve Form ID”. This script will allow you to get the Form ID of the current Google form.
Step 4
Paste this code in the script section:
Code Block |
---|
function getActiveFormID(){ const id = FormApp.getActiveForm().getId(); console.log(id); } |
Step 5
Click Debug to check the script and click Run.
...
Step 6
Save the output for use in future steps.
Step 7
Create another script and name it “Registration/Followup Form Script” depending on which kind of form you are using.
Step 8
Paste this code in the script section:
Code Block | ||
---|---|---|
| ||
function sendPostRequest(e){ var form = FormApp.openById('FORM ID'); var responses = form.getResponses(); var formDataLast = responses[responses.length - 1]; var formData = formDataLast.getItemResponses(); var sendData = {}; // Change to object for(var k = 0; k < formData.length; k++){ var newTemp = formData[k]; var key = newTemp.getItem().getTitle().toString(); var val = newTemp.getResponse(); sendData[key] = val; // Add key-value pair directly to object } Logger.log(JSON.stringify(sendData)); var options = { 'method': 'post', 'contentType': 'application/json', 'payload': JSON.stringify(sendData) }; UrlFetchApp.fetch('POST URL from Power Automate', options); } |
Step 9
Replace ‘FORM ID’ in line 2 with the Form ID saved previously in Step 6.
Step 10
Replace ‘POST URL from Power Automate’ by navigating to the first step in the Power Automate flow and copying the URL.
...
Step 11
Click Debug and click Run. If the script is successful, you will see the JSON parsed object data in the output screen.
Step 12
Go back to Power Automate and continue building the flow and follow all steps in the main tutorial here.