You are on page 1of 19

Power Automate and Survey123

Basic Flow Set-up

Table of Contents
Power Automate and Survey123 ..................................................................................................................................................... 1
Basic Flow Set-up ........................................................................................................................................................................ 1
1. Preface ............................................................................................................................................................................ 2
2. Quick Power Automate Overview ....................................................................................................................................... 2
3. Service Accounts ............................................................................................................................................................. 3
4. Survey Requirements ....................................................................................................................................................... 3
5. Custom Connection ......................................................................................................................................................... 3
6. Save As You Go ................................................................................................................................................................ 3
7. The Flow .......................................................................................................................................................................... 4
8. High-Level Overview ....................................................................................................................................................... 13
Appendix I – Fixing an old Custom Connection ............................................................................................................................. 14
Appendix II – Webhook settings ................................................................................................................................................... 15
Appendix III – Custom JSON ........................................................................................................................................................ 16
Appendix IV – templateItemId ..................................................................................................................................................... 17
Appendix V – Template in Power Automate ................................................................................................................................... 18
Appendix VI – Special Notes ........................................................................................................................................................ 19
1. Preface
My flows for S123 are split into two parts: Stage 1, and Stage 2. This is primarily to support error handling to ensure a highly reliable
corporate environment.

I have both stages saved as “Templates”, and all subsequent flows I make are based on these two templates by saving a copy of the flow
and then editing that saved copy (see Appendix V – Template in Power Automate for more details).
This is only a basic guide and will cover a single-stage flow for generating reports. I plan on releasing a more comprehensive guide in
the future that covers the two-stage flow mentioned above.
I would consider the flow described below to be very basic. It serves as a good introduction to Power Automate and Survey123 but is not
something that I would deploy as a large-scale corporate solution.

2. Quick Power Automate Overview


No, this is NOT an in-depth or extensive guide to Power Automate 1. I just want to make sure we are on the same page with layout and
terminology.

1. New flow – This is where I start new projects if I am starting from scratch.
2. My flows – Contains all your flows. I typically spend most of my time on this tab.
3. Connections – Enterprise users like me will need this more often than AGO users. Go here to update login credentials or
refresh connections.
4. Custom connections – Again, Enterprise users will care more about this than AGO. You need to go here to create the Custom
Connector mentioned in the Custom Connection section.
5. List of Flows – This is a list of all your flows ordered by Modified date. At this time, the order method cannot be changed.

1
For more information, try https://learn.microsoft.com/en-us/power-automate/getting-started
1. Insert a new step – Hovering over an arrow allows you to add an Action between two existing steps.
2. Dynamic Content – When you click into a field, you get a popup. Dynamic Content is selected by default, and it contains a list
of all dynamic content from your Flow’s Trigger as well as every Action above the Action you are configuring.
3. Expression – Allows you to write Expressions. E.g., utcNow() returns the current time.
4. Add an action – The same as #1, but at the bottom of groups and with slightly different terminology.
5. + New Step – The same as #1, but at the bottom of the page.
6. Context Menu – Allows you to configure Run After settings (e.g., error handling) as well as action-specific settings (e.g.,
maximum loops).

3. Service Accounts
You need an account to log into Power Automate, and Power Automate requires an external account to set up a connection to your
Portal. I highly recommend that you set up a service account for both. I also highly discourage the use of a named user for those
service accounts (I mean, if they are a named user, they aren’t service accounts anyway). E.g., If Fred’s personal account is holding
everything together and Fred decides to get a new job, have fun swapping all of Fred’s services to a new account! vs. You use an
unnamed service account to hold everything together and Fred gets a new job, you at least don’t have to worry about services failing
when IT inevitably disables Fred’s account!

4. Survey Requirements
Not applicable for a basic implementation.

5. Custom Connection
This step is the only real difference between AGO and Enterprise now…
AGO, skip this step.
Enterprise, follow the instructions in the Knowledge Base (KB) article below.
Create an ArcGIS Survey123 connector for Microsoft Power Automate for use with ArcGIS Enterprise

ATTENTION: To Enterprise users with per-existing Custom Connections, your connection may be out of date. If that is the case, you WILL
NOT see the new “Create report” connector. To fix that, see Appendix I – Fixing an old Custom Connection.

6. Save As You Go
Sometimes things go wrong in Power Automate and you can’t edit your flow properly, meaning your only course of action is to refresh the
page and lose all your unsaved work. Power Automate does NOT let you save a flow if there are ANY errors in it.
This is a huge limitation/liability when working on new projects, and hopefully it will change in the future.
So… save your work regularly!
7. The Flow
Start a new blank flow. The fastest way is: + New flow > Instant cloud flow > Skip

In the top right corner, you may see the “New designer” toggle 2. Toggle this OFF3.

+ Trigger
AGO: Search for “survey123” and choose “When a survey response is submitted”.
Enterprise: Select the Custom tab and click “When a survey response is submitted”.

2
This button tends to move around the page as Microsoft progresses their testing of AI and flows, so it may have moved by the time you
are reading this.
3
I always turn this off for two main reasons: 1) It doesn’t work for complex flows, which most of mine are, and 2) I find it clutters the
screen.
Now that your trigger has been added, you need to select a survey for it to point to. As soon as you save and turn ON this flow, a
Webhook will be created for whatever survey is listed here (check out Appendix II – Webhook settings for some more info).

I suggest you set this flow up as a template by selecting a survey that is always present, but never used (see Appendix V – Template in
Power Automate for more details). In my case, I have a “Demo Form” that I keep around for general testing and saving random
features/content. This is “my” survey that only I use, and so it perfect for this role.
When you save and turn ON a flow that uses the “When a survey response is submitted” Trigger, whichever survey you have selected in
the dropdown will have a pending update in the Field App. Users must download this update for their survey submissions to trigger the
flow.

Using a “dummy” survey to fill this dropdown is a nice buffer in case your template ever gets mistakenly turned ON. With such a set-up,
no “live” surveys will ever be affected by such an eventuality.

+ Initialize Variable × 2
Format the variables as per below.
The only thing you need to change here survey-to-survey is the Value for surveyName. I recommend that this be both unique and
recognizable. E.g., I used “DEMO” for my Value in this demonstration. If I ever see “FLOW FAIL - DEMO” in my inbox, I will know exactly
what survey that email is for (I’ll cover the “FLOW FAIL” component below).

While I typically don’t name unique steps like Triggers, it is important to name all steps of your Flow for clarity. I recommend leaving the
default text and just adding onto the end. E.g., “Initialize variable – jobStatus” rather than “jobStatus”.
+ Scope
We are working within this scope until specified otherwise! This is a big part of error handling.

By the way… In subsequent steps, you will notice that I try to leave a “cookie trail” for you, so you know where to put things. You can
check my screen caps to see what I ended up naming my different steps. For example, I named this first Scope as “Scope – Report”. This
is what I use in my “cookie trail” below! Feel free to name your steps whatever makes the most sense to you though.

+ Scope – Report > Create Report

Field Required Description


Survey Yes This should match your Trigger.
Feature layer Yes There is most likely only one option here.
Report template Yes This is your Feature Report. If this dropdown menu is empty, you need to go to the Surveys Site and
upload a Feature Report.
Feature object ID Maybe You must enter a value either here, or in Feature WHERE clause below. I recommend sticking to
this for now.
Feature WHERE Maybe You must enter a value either here, or in Feature object ID above.
clause
Report name Yes This is what the output will be named. Do not put the file extension here.
Format Yes This is your file extension. [docx] is selected by default. Choose either [docx] or [pdf].
Show advanced No There is only one option here: UTC offset.
options I use this in all my main flows, but I am skipping it for this basic flow.
To fill in your Feature object ID, click into the field and search for “objectId” in Dynamic Content (see item #1 in Appendix VI – Special
Notes for an important note).

+ Scope – Report > HTTP

Field Value
Method GET
URI Search Dynamic Content for “url” from your Create Report step.

ATTENTION: I will only mention this ONCE, but it will come up several more times in the flow! You will see duplicates of many values
from Esri’s “Create report” step, such as “url” pictured below. Esri added the “… of the first result file” options specifically for use in your
flow. The other option should be disregarded entirely.

Why, you may ask. Because the “Create report” step is actually a loop. Let’s put this in the context of Survey123: the Create Report step
is a Repeat, “url” is inside the repeat, and “url of the first result file” is outside the repeat. If you select a value that exists within a Repeat
(aka, an array) within Power Automate, it tries to be smart and will add that step you are working on in an “Apply to each”.
+ Scope – Report > Set variable

Field Value
Name Search Dynamic Content for the “jobStatus” Variable.
Value Search Dynamic Content for “jobStatus” from your Create Report step.

We are now done with the first Scope!

+ Scope
This is our second Scope, and our first error handler.

+ Scope – Report Fail > Send an email


This email should go to your Service Account, and it’s only sent when something goes wrong. As such, it only needs to be as pretty as
you want it to be. The email below is what my “error” emails actually look like.
Field Value
To This should be your service account and should never need to change once set.
Subject I’d recommend something similar to: FLOW FAIL – {surveyName}
Body When something goes wrong, it can be difficult to track down the exact flow run where the issue occurred.
That is why I highly recommend you add the following Expression. It will generate a dynamic URL to the exact
flow run that failed, thus saving you a bunch of time.
concat('https://emea.flow.microsoft.com/manage/environments/', workflow()['tags']['environmentName'], '/flows/',
workflow()['name'], '/runs/', workflow()['run']['name'])

Just copy-paste the above text into the Expression field and click OK

If you have multiple email accounts added to Power Automate, keep in mind that every time you add a “Send an email” step, Power
Automate defaults to the first email in the list alphabetically. You will have to manually change it each time by going into the Context
Menu.

+ Scope – Report Fail > Terminate


This ensures that 1) No subsequent steps trigger, and 2) You can more easily pick out the failed run from your Flow’s History. It’s not
really necessary for such a small flow, but we are also trying to build good habits.

Configure the Run After for Scope – Report Fail to be the following:

Second Scope complete!

+ Condition
Conditional values are case-sensitive! Ensure you enter esriJobSucceeded exactly as shown.

This step is very important because of how the Create Report step functions. Basically, if something goes wrong on Esri’s end while
generating your report, Esri will still successfully pass along that failure notice to Power Automate. As a result, the Create Report step
within Power Automate will succeed! Consequently, you need to manually tell Power Automate that something went wrong.
Configure the Run After for Condition to be the following:

+ Condition > If no > Send an email


This email should be identical to the “error” email above. Feel free to copy that previous email down to here (just give it an appropriate
name).

+ Condition > If no > Terminate


+ Condition > If yes > Send an email
From here on it’s very much up to you. The only thing I really wanted to show is the attachment of the Feature Report. Be sure to click
“Show advanced options”.

Field Value
Attachments Name -1 Search Dynamic Content for “name” from your Create Report step.
Attachments Content Search Dynamic Content for “body” from your HTTP – Get Report step.

+ Copy-Paste ‘Scope – Report’


This is the final step!

Copy Scope – Report Fail to your clipboard.

Paste it under Condition


Rename your new Scope to Scope – Condition Fail, and then configure the Run After to be the following:

Don’t forget to also rename the “Send an email” and “Terminate” steps.

☺ Done!
This is it!

You should now have a basic flow to generate a Feature Report upon survey submission, and then email that Feature Report.
8. High-Level Overview
Appendix I – Fixing an old Custom Connection
If you have a pre-existing Custom Connection for Power Automate that does not have the new Create Report action, you have three
options:
1. Replace your old Custom Connection with a new one [Not Recommended]. That also means you must update every flow that
used the old Custom Connection, and all your users need to update all their surveys to get Power Automate working again.
2. Have two Custom Connections running side by side [Not Optimal]. Probably the lowest effort solution. There is no user impact
here unless you need to update an old flow to use the new Custom Connection. You will end up with a mix of flows using the
new and old Custom Connection.
3. Update your old Custom Connection [Recommended]. A little more complex, but has zero user impact, and all old Custom
Connections are automatically updated.
Procedure:
1. Follow along in Esri’s Guide until Step 5, then return here.
Attention: When I tried to recreate this step, I ran into an odd error. I was unable to save my Custom Connection, and kept getting
“Description must be written in English”. While I don’t expect that this error is common, if it crops up for you, here is the solution:
Delete all of Esri’s text from the Description text box and paste in plain text (no numbers or special characters). Just be sure you have at
least 30 characters in the text box, or you will get another error telling you to add more characters… Ultimately, I just copy-pasted
“Description must be written in English.” Into the Description text box several times. Problem solved.
2. Open your new Custom Connection in one tab, and your old Custom Connection in another.
3. Go to 3. Definition in both tabs
4. Toggle ON Swagger editor

5. In your new Custom Connector, copy everything: Ctrl + A then Ctrl + C


6. In your old Custom Connector, paste the new code: Ctrl + A then Delete then Ctrl + V (Yes, I am paranoid, and I like to see
that the text box is completely empty before I paste in new code)
7. Toggle OFF Swagger editor
8. Check that you have all new actions are available (listed below)

9. Click Update connector


Appendix II – Webhook settings
After you save and turn ON a flow that uses the When a survey response is submitted Trigger, a webhook will be created for you.
1. Go to the Surveys Website (https://survey123.arcgis.com/surveys)
2. Select the survey you are working on and go to the Settings tab
3. Click Webhooks
4. Click the pencil icon to edit your webhook.

There is likely only one webhook. However, each time you save a new flow that uses the “When a survey response is submitted” Trigger
(and turn it ON), a new Webhook will be created. My “Demo Form” that I use as a Power Automate template has 20 or so webhooks…
another excellent reason to have a template set-up like I describe here!

If you were messing around in Power Automate and have a bunch of Webhooks, you only have a single flow, maybe just delete all the
extra Webhooks.
5. All items are checked by default, except for “Existing record edited”. If you are allowing records to be edited, ensure that you
check this ON
Appendix III – Custom JSON
At minimum, you need two steps:
1. When a survey response is submitted Custom Trigger; and
2. Literally any other step so Power Automate saves and runs (I typically use Compose with the Trigger Body for content – but it
doesn’t really matter).

Steps:
1. Select the survey you would like custom JSON for

2. Save your flow and turn it ON


3. In S123, ensure you get the pending update. Then, fill out and submit your form. It is important to take note of what you want to
show up in your JSON. At minimum, I have two recommendations: 1) Don’t leave content empty if you want to use it. Put at least
something in there. 2) If you are using repeats, only add one single record to the repeat. Adding multiple records will just make
your life harder.
4. Go back to Power Automate and click the “refresh” button in the top right of your “28-day run history”. Power Automate
detects that a survey was submitted almost instantly, but sometimes it takes a second or two to show up. You may need to click
refresh 1-2 times. Once your flow run shows up, click the date/time to enter the run.

5. Expand your Trigger, then select and copy Body

6. Go to VS Code and paste the JSON into a new file. At minimum, you should change all the values to null (this will save you from
errors and headaches later). Beyond that, I also recommend stripping out anything you don’t plan on using since it makes
working in Power Automate simpler.

If you are working with repeats, you may wish to also leave the uniquerowid and parentrowid fields. Depending on your task, these may
be critical to eliminating duplicate entries or entering data into a database.
Appendix IV – templateItemId
6. Go to the Surveys Website (https://survey123.arcgis.com/surveys)
7. Select the survey you are working on and go to the Data tab
8. Click Report
9. Upload a Feature Report, if one is not uploaded already
10. Physically select the Feature Report from the dropdown menu. Do this even if the Feature Report you want already appears to
be selected… because it isn’t (for this purpose).
11. Look at your URL, the templateItemId for that Feature Report is there
Appendix V – Template in Power Automate
When I talk about templates in Power Automate, I am not referring to the “Templates” page, but rather flows I have set up in the “My
flows” page with placeholders (e.g., “Demo Form” as the Trigger, as I describe above) and leave turned OFF.

When I want to use one of these “templates”, I go More Commands > Save As, and then edit the copy. This allows me to set up new
surveys with a robust and functional flow in just a few minutes.
Appendix VI – Special Notes
This is just a space for me to add miscellaneous notes that don’t fit anywhere else. I will add to here as I remember things.
1. Sometimes when you search for a variable in Power Automate, it will not appear. This is a bug. You can circumvent this bug by
doing the following:
a. Go to Expression and type =

b. Go back to Dynamic content and delete the =

c. Scroll through Dynamic content and locate the missing variable. (This fix will disable type-to-search but WILL show all
the missing variables).
2.

You might also like