What’s the time a flow was triggered locally to the user who triggered a flow? How do we get the local trigger time?
When you create a flow that is triggered by the creation of a record inn Microsoft Dataverse, you might find that the Creation time doesn’t match your actual time.
In my example below I created a new record at 10:16 am and the Created On time in my When a row is added, modified or deleted trigger tells me that it was created at 9:16
Whatever the timezone is used by the data, it may not match the tiemzone fo the user. So how do we get the time locally to the person triggering the flow.
Finding the user
First steps first, we need to find out who the user is that triggered the flow by adding a new account to my Dataverse database.
to get the user you can use the Get a row by ID action.
This will give you the details of the user, but not their timezone!
For the timezone we will have to call Microsoft Graph.
Get the timezone
To get the timezone used by the user I’m going to look at the Mailbox settings.
If you are really worried about collecting too much information you could also use the following endpoint instead:
The above endpoints will collect the following setting in your Outlook:
Using the endpoints in a flow in Power Automate
To use the end point an HTTP action will need to be added to our flow that we created so far. If you need any more information on how to create an app registration in Azure then please look at my post create a Microsoft Teams team template.
The only difference is that you will need to give consent to use the following permissions in your app :
And all the information returned by the above HTTP action and collected with two Compose actions:
The expression in the first Compsoe is:
And the second one is (this can be selected from Dynamic content as well):
Get the local trigger time
So we are now nearly there.
We have a time to convert and we have a time zone to convert to. Using the ConvertFromUTC function it is now possible to get the actual time matching the local trigger time when the user created a new record:
convertFromUtc(outputs('time'), outputs('timeZone'),'yyyy/MM/dd hh:mm')
In the above code there are of course other date formatting options possible. Please look at my formatDateTime posts fro more details on that.