EDIT (7/12): You can download the Flow from https://1drv.ms/u/s!AvzjERKFC6gOwCqKnnAvMZA6mDsW if you just want to jump straight into exploring the actual Flow, instead of reading the article.
DateTime and Timezones seem to be the flavor of the month, so I thought I will take a crack at the problem as well. Coming from CRM background and spending a lot of time fiddling around the internal schema to understand the plumbings I came up with the following approach which I believe is decoupled and flexible.
In CDS, there is an entity called “UserSettings”, which stores a whole bunch of information regarding the user preferences. If you have used the awesome XrmToolBox tool called “UserSettings Utility”, you would remember this screen.
The “UserSettings” entity is the source of this information. So, why not use the same for managing the timezones and datetime formats?
For re-usability, I want to create a Flow that just returns me the timezone information based on the executing user. Here is how it looks.
Let us understand this step by step.
This is the HTTP trigger, which can take in a parameter for activedirectoryguid. This is the unique identifier for the Office 365 user.
Get the Office 365 profile of the current user. If the activedirectoryguid is not passed in step 1, the intention is to use the current user’s Office 365 information.
Step 3 & 4:
Initialise the activedirectoryguid variable, and query the CDS entity “Users”, and retrieve the user that matches the activedirectoryguid.
Since activedirectoryguid can be passed on the trigger as well, I use the following coalesce expression, to set the variable to either the passed value on the trigger or from the Office 365 profile in step 2. This is the expression.
Step 5 & 6:
Retrieve “User Settings” entity and the associated “Time Zone Definitions” record based on the user’s timezone.
The filter for User Settings is
The filter for Time Zone Definitions is
This is the last step, where we return all the format and timezone information.
Below are the expressions for the returned properties:
Now let us look at some sample output. For a user located in US, here is how the output of the Flow looks like.
Compare this with someone who is in Australian timezone.
Since this Flow now contains the logic for getting the formats and timezones, it can be utilised for another Flow that needs this information. For example look at the sample Flow below
Below is the expression, I use to convert the “createdon” returned by the CDS Get Record, step which returns the datetime in UTC.
If you compare this Flow output and the record properties from Dynamics 365, it becomes obvious that the datetime and format is correctly displayed. Note that the CDS connector returns the datetime in UTC.
Initially I wanted to call the Flow that returns the formats and timezone using the “Start Flow” action on the Flow Connector, but it doesn’t seem to be picked up the response, so I had to resort to the whole HTTP action, which is not ideal.
It seems “Start Flow”, simply enables the Flow, does not actually run the Flow. Not sure why it is named in a misleading way.
Hope this is helpful.