Creating Power Automate (aka MS Flow) webhooks for Survey123 surveys in ArcGIS Online - Part 2

4695
2
11-17-2019 04:00 PM
zkovacs
Occasional Contributor III
2 2 4,695
Part 1 of this article can be found here.

In Part 2 we'll have a look at how we can add the survey's time to the webhook and how to convert time zones and format the date/time string.

Add survey time to your notification email

Survey123 submits date and time from your survey form in UNIX format. This means that the date & time value will be in milliseconds. By default, you cannot really display this in any usable format unless you convert it first. There are many time converters available on the internet, like this one to do that. However, we don’t need to use these in Flow as we can set up a function for this.The steps below are based on the webhook we created in Part 1 - but can be applied to any existing or new webhook (assuming that your survey has a date/time field in it).

1.   Click on Add an action under the If yes branch of your condition 
No alt text provided for this image
2.   Search for ‘add to time’ and select the action from the result list.
No alt text provided for this image

3.   To edit the action, click into Base time and switch to the Expression tab in the context dialog:
No alt text provided for this image

4.   Enter the expression* into the function box (fx) and save your webhook:
addseconds('1970-1-1',div(triggerBody()?['feature']?['attributes']?['survey_datetime'],1000))

NB:
This example assumes that the date/time field in your survey is called 'survey_datetime'. If it's different in your survey, you need to modify the expression accordingly.

* I am aware that a similar expression exists in this blog article, but all the date formatting strings I've tried gave me an error in Flow. I believe Flow was updated since that article and no longer accepts the formatting string as part of the expression. When leaving the formatting string out, the expression was accepted and works just fine.

So, what does the above snippet do?

The addseconds() function adds the seconds specified to a base time. The base time for Unix is 1st January 1970, hence the '1970-1-1' part as base. Then in the second parameter we call the dynamic value from the ‘survey_datetime’ field – but as this is in milliseconds, we need to divide this by 1000 as the addseconds() function needs a value in seconds. That’s why we added the div() function, which provides this division for us.

You can add a static hour/day/month/etc. value to this calculation specifying the Interval and Time unit in the step. (For example if your device's clock is misconfigured.) We don't need to add anything in our case, so we just set it to '0 Hour'. 
No alt text provided for this image

Convert time zone and format string

As discussed above, your survey's date & time is submitted in UNIX format (also known as UNIX Epoch, UNIX timestamp or POSIX time) which starts at midnight (UTC) on 1st January 1970. If your local time zone is different from UTC, you may want to convert the calculated time into your correct time zone.

The below steps assume you have completed the time calculation step in the previous section.

1.   Click on Add an action under the If yes branch of your condition.
No alt text provided for this image
2.   Search for ‘convert time zone’ and select the action from the result list to add it to your flow. 
No alt text provided for this image
3.   Click into Base time, then in the Dynamic content tab of the context dialog select Calculated time – this is the function we just created in the top half of this article. 
No alt text provided for this image
4.   Set up the Source time zone (it must be UTC) and your Destination time zone, then choose a Format string you want to use. 
No alt text provided for this image

In Part 3 we will discuss how to include the calculated/converted time and other dynamic content in the notification email and where to find additional settings for your webhook.
2 Comments
MattWalder
New Contributor

What should be placed in the interval section as it is a required field?

zkovacs
Occasional Contributor III

Apologies, the images disappeared from the post (might be to do with some GeoNet updates?) but I have replaced them. You should be able to see that under Step 4, I set it to '0 hours'. I hope this helps.

About the Author
GIS specialist with over 20 years of professional experience providing consultancy, technical support, training and delivering high quality solutions and support for projects that have a requirement for spatial data interpretation and analysis. Main areas of expertise include (but not exclusively) data management, spatial analysis and modelling, cartography, desktop, mobile and web GIS, Python/ArcPy and webhooks with Power Automate/MS Flow. Former Esri Hungary and Esri UK staff.