Wednesday, 28 November 2018

How to display a date field value correctly in an email in Flow

23:12 Posted by Benitez Here , , , , , , No comments

In my previous blog post and vlog I covered how to reference related entity data. The last use case was to send an email to the contact associated to the Case where the Created On value is included in the email message content. Currently today we're used to configuring this through the Form Assistant by selecting the Created On field of the Case.



If you do this in Flow using the Get Record action and Send email from Shared Outlook Mailbox, it'll look like the following.


Yes, a true WTF moment. Welcome to another WTF blog post.

Why does it display in this manner?

I stumbled across this when I was in the process of converting my Dynamics 365 workflows into Flow for the Dynamics 365 Saturday NZ conference earlier this year. I knew I needed to use the Get Record action and when I did it was showing up as seen in my screenshot above.

That's when I came across Stephen's blog post in the Flow community site. If you don't know about the Flow community site, you should definitely check it out. There's lots of useful nuggets in there.

Anyways Stephen's blog post explains that Flow treats Date and Time in UTC and talks about using a particular action. The other thing to take note of is that Dynamics 365 also stores Date and Time as UTC. When we see the date and time in the user interface it will be shown in the timezone of the user if it's defined as User Local. For further information on the other Date and Time definitions, refer to this docs.microsoft.com article.

Using the convert time zone action in Flow

This action is pretty simple to understand.


  1. Base time - this is where you need to reference the Dynamics 365/CDS field. In my scenario it's the Created On field of the Case
  2. Format string - this is where you can define the format of the date and time. You can either choose from a list or make your own
  3. Source time zone - this is where you set the value to UTC
  4. Destination time zone - this where you set the value to the local time zone
Once you have this Flow action set up, you're good to go. In your email message you can now reference the convert time zone action. 


When the recipient of the email views the email message they will now see the the date displaying correctly in a more end user friendly manner.

Is there any value in this "extra" configuration step?

OK you might be outraged that you need to go one step further in Flow to get the date and time displaying correctly in an email message compared to the minimal configuration required in Dynamics 365 workflows

However the advantage I see is that you now have the power to format the date the way you want it to. Those who are familiar with Dynamics 365 will know that
  • if you want to have different formatting in Email Templates or in an Email activity created from a Dynamics 365 workflow, you have to turn to some type of custom method
  • you can change the formatting of date and time in Settings so that it shows as desired but this applies globally in Dynamics 365, it's a system wide setting
Here are a few posts that demonstrate people asking about how to change the format of date and time outputs
If you turn to the developer guide on docs.microsoft.com, you'll see a bunch of information on how to to convert date and time fields through code.

By using the convert time zone action in Flow you have the power to choose what format you want as the output in your email message without any code.

Summary

Use the convert time zone action in Flow to display a date and time field value in an email message. If you don't, it will display as UTC in the email message.

If this has helped you, tweet to let me know. Thank you.

This Flow is available in the TDG PowerApps Bank.

Happy Flowing!

#WTF #FlowFever #TDG

0 comments:

Post a Comment