Generate Feature Report in Power Automate directly from Feature Layer

334
3
02-20-2024 09:54 AM
abureaux
MVP Regular Contributor

EDIT: Just going to link back to my main Power Automate post to keep things connected.

There are different ways to do this, but I thought that I would showcase the one I am going to be using relatively soon.

The idea is that the S123 webhook that listens for submissions isn't 100% reliable, and a missed submission can be detrimental to a project. However, even when a submission skips the webhook, it still lands in Portal. The goal of this workflow is to watch the Feature Layer directly, and run processes off of that.

General Steps

1.
I started by adding a single field to a survey. This will be your "control field". You can name this field whatever you want, and the values within it can be whatever makes sense to you. My "control field" will be a TRUE/FALSE:

abureaux_0-1708449050127.png

Now I can tell which items haven't been processed yet.

2.
In Power Automate, add a trigger. For my tests, I used a Manual Trigger, but once in production, it will be on a Schedule.

abureaux_1-1708449347409.png

3.

Add a new step. Search for "Esri" and click on your proper environment (Enterprise = Purple and AGO = Orange).

abureaux_3-1708449443389.png
More details on these connectors is here.

4.
Select "Get data from feature layer". Configure the three required steps by pointing to the survey you are building for, and choose JSON as the output.

The only other important item here is the Where clause (e.g., prime_process = 'FALSE'). Without that, you won't process the proper item(s). I am using my newly created "control field" referenced in Step 1.

"Return geometry" is optional and you can probably leave that as "Yes".

abureaux_2-1708449388322.png
More details on connector limitations is here (e.g., Return Geometry).

5.
Add "Update a record in a feature layer". The first two fields are again the survey you are building for.

The third field should be "ObjectID". Then, in the fourth field, select your ObjectID from dynamic content. This will automatically nest your step in an "Apply to each"... That makes sense, because even if there is only one item in your Feature Layer, the operation is an array.

Lastly, find your "control field" and toggle it to indicate the item was processed. (e.g., prime_process = TRUE)

abureaux_8-1708450138897.png

6.
Before continuing, take a step back and select the Settings for your new "Apply to each".

abureaux_6-1708450033347.png

Then turn on "Concurrency Control" and set it to "1"

abureaux_7-1708450067181.png

This ensure that we don't double-process an item by only handling one at a time.

7.
Add "Create report", point it to the same survey you are building for, and configure as necessary.

abureaux_9-1708450463360.png

8.
Add "HTTP". There are only two things to set here:

abureaux_10-1708450507120.png

When adding the "url" from dynamic content, be sure you grab the "url of the first result file", as indicated below.

abureaux_12-1708450581697.png

9.

Add "Send an email" (or whatever steps you want really. This is just an example).

The only really important thing I wanted to showcase here is the attachment. For the name, there will be two options, just like "url". Be sure to choose "name of the first result file". For the Attachment Content, use your HTTP's body. 

abureaux_13-1708450662276.png

10.
And lastly, add a second "Update a record in a feature layer".

Configure it the same as the first, but set the "control field" back to FALSE. This is our (super basic) error handler.

abureaux_14-1708451010196.png

Then, click on the ellipses (...) and select "Configure run after" and choose "has failed" and "is skipped". Then, hit "Done".

abureaux_15-1708451073538.png

...

In the end, I got this:

abureaux_16-1708451139209.png

Very simplified flow. But it's at least a starting point. I'll be building out my process form here to add in a bunch more steps and redundancy.

3 Replies
RobertAnderson3
MVP Regular Contributor

Thank you so much for putting these guides together @abureaux !

I'm going to have to update all of my When a survey response is submitted triggers for sure, I haven't prioritized it yet because the webhooks that create reports, the user will see it hasn't been created and just submit it again, a nuisance but manageable.

I know it's the basic first pass, but a suggestion I might include is putting the actions Update record (1), Create report, HTTP, Send Email in a Scope, and then having the error catching Update record (2) set as a run after fail/skip on the Scope, just in case an earlier action than the email fails.

And I like the HTTP GET as an alternative to the OneDrive actions in other samples as well (and that custom connector look will always throw me off, I'm so used to the green AGOL one! Haha)

0 Kudos
abureaux
MVP Regular Contributor

Oh, I totally agree! I thought to myself... these should really be in a scope. But I was lazy and convinced myself this was just a "proof of concept". (The "Skipped" part of Run After kind of works in this case, but it isn't a good practice).

Good point on the connector. The custom red was me having fun with soft corp branding, not expecting anyone else to ever see it. I may make a new Custom Connector purely to grab a screen cap of so I can MS Paint that standard green connector in for the future.

RobertAnderson3
MVP Regular Contributor

Haha fair enough! I had a feeling you'd have thought about it but went basic for the proof of concept. I didn't realize the Skipped would trigger in that case, I thought a failure would just end things.

Ah I just figured it was the default custom connector and I didn't recognize it because of that, I didn't know you could personalize them, that's pretty cool actually! It's just a small detail in these guides though.

0 Kudos