{"id":110888,"date":"2017-10-22T07:03:13","date_gmt":"2017-10-22T14:03:13","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/email-digest-date-manipulations\/"},"modified":"2017-10-22T07:03:13","modified_gmt":"2017-10-22T14:03:13","slug":"email-digest-date-manipulations","status":"publish","type":"power-automate","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/email-digest-date-manipulations\/","title":{"rendered":"Intermediate | Flow of the Week: Get me an digest of today\u2019s inspections in a single email"},"content":{"rendered":"
This week, we\u2019ll look at a Flow scenario brought to us by someone from our user community \u2013 daily digest email of scheduled site inspections. With this Flow, we\u2019ll demonstrate two common Flow patterns \u2013 how to work with dates and how to join data.<\/p>\n
Let\u2019s imagine that we store our site inspection reports in a SharePoint list. An inspection consists of fields like the Site Name, Site Location, Technician, Inspection Date, and Notes.<\/p>\n
<\/p>\n
Our flow runs every day and gets all inspections that are to be conducted today using the Filter array action. Once we\u2019ve got today\u2019s inspections, we\u2019ll create an HTML table with each row. Finally, we\u2019ll send an email that has all the data collated together.\u00a0\u00a0<\/p>\n
<\/p>\n
Let\u2019s look at the flow in detail. \u00a0<\/p>\n
Let\u2019s schedule our Flow to run every day at 8AM. With recent changes to the Recurrence action, you can now easily and precisely set when a flow should start.<\/p>\n
<\/p>\n
Once the flow has been triggered, we\u2019ll Get all list items and then use a Filter array action to hone in on just the work items whose Inspection Date is marked as today.<\/p>\n
<\/p>\n
The magic sauce to getting today\u2019s inspections is the ticks()<\/strong> expression. Given a timestamp in string format, the Ticks expression returns the number of ticks (100 nanosecond intervals) since 1st<\/sup> January, 1601. By using ticks, we can compare two different timestamp values.<\/p>\n In our flow, we\u2019ll check if the number of ticks for the Inspection Date field (the left hand side of the Filter array action) are equal to the number of ticks for Today\u2019s date (the right hand side of the Filter array action). i.e. \u2013<\/p>\n ticks(item()?[‘Inspection_x0020_Date’]) <\/strong><\/p>\n =<\/strong><\/p>\n ticks(utcNow(‘MM\/dd\/yyyy’))<\/strong><\/p>\n In SharePoint, the Inspection Date is stored with only the Date format, e.g. 10\/20\/2017. The ticks() expression will calculate the number of ticks for 10\/20\/2017 at 12:00AM. Similarly, the number of ticks for utcNow(), which is today\u2019s date and time must be qualified with the ‘MM\/dd\/yyyy’ format, to ensure that we get the ticks for today\u2019s date at 12:00AM and not the ticks for the current time (which would be greater than 12:00AM)<\/p>\n Now that we have a filtered array of today\u2019s inspections, we\u2019ll create an Apply to each loop to iterate over each result. In the Apply to each loop, we\u2019ll use the Compose action to create an HTML table row per inspection.<\/p>\n <\/p>\n To reference inspection fields, like the Site Name or Title, we\u2019ll use an expression like the following: items(‘Apply_to_each’)?[‘Title’]<\/strong>. We\u2019ll use the same approach to reference the Location field – items(‘Apply_to_each’)?[‘Site_x0020_Location’]<\/strong> and the Display Name of the Technician – items(‘Apply_to_each’)?[‘Technician’]?[‘DisplayName’]<\/strong>. Note \u2013 Technician is a Person field in SharePoint.<\/p>\n Outside of the Apply to each loop, we\u2019ll use the Send an email action. In the action, set the Is HTML property to Yes and then insert the results of the Apply to each loop as a table in the Body.<\/p>\n <\/p>\n To get the results of the Compose action, we\u2019ll use the join(actionOutputs(‘Compose’),”)<\/strong> <\/strong>expression. This simply collates each output (i.e. an HTML row) using the blank character as a separator.<\/p>\n Now every day, you\u2019ll get an email like this with details about today\u2019s inspections.<\/p>\n <\/p>\n You can learn more about the expressions used in this post in the Workflow definition language documentation<\/a>. We hope you found this post useful! As always, please share your feedback using the comments below. If you have a question or idea, leave it below or head over to the Microsoft Flow Community<\/u><\/a>.<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n","protected":false},"excerpt":{"rendered":" In this week’s Flow of the Week, we’ll look at how you can create a flow that sends you a digest of today’s scheduled inspections in a single email.<\/p>\n","protected":false},"author":350,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","power-automate-category":[2590],"power-automate-tag":[2536,2551,2638,2645],"coauthors":[2911],"class_list":["post-110888","power-automate","type-power-automate","status-publish","hentry","power-automate-category-flow-of-the-week","power-automate-tag-dates","power-automate-tag-digest","power-automate-tag-intermediate","power-automate-tag-join"],"yoast_head":"\nCreate an HTML table for filtered results<\/h2>\n
Send an email with an HTML table<\/h2>\n