{"id":1307,"date":"2017-06-19T10:10:49","date_gmt":"2017-06-19T16:10:49","guid":{"rendered":"https:\/\/toddbaginski.com\/blog\/?p=1307"},"modified":"2017-06-19T10:10:49","modified_gmt":"2017-06-19T16:10:49","slug":"use-dynamic-odata-filter-values-in-a-microsoft-flow-sharepoint-getitems-action","status":"publish","type":"post","link":"https:\/\/toddbaginski.com\/blog\/use-dynamic-odata-filter-values-in-a-microsoft-flow-sharepoint-getitems-action\/","title":{"rendered":"Use dynamic ODATA Filter values in a Microsoft Flow SharePoint GetItems Action"},"content":{"rendered":"<p>While working on a project for Microsoft recently I needed to use a Microsoft Flow to return all list items from a SharePoint list that were not approved in the last week.<\/p>\n<p>To correctly return the list items, I needed to create this ODATA Filter expression:<\/p>\n<pre>Status ne 'Approved' and Date gt datetime'2017-06-08T18:21:58.4807681Z' and Date lt datetime'2017-06-15T18:21:58.5276427Z'<\/pre>\n<p>In the code that follows, I have replaced the datetime values with placeholders to demonstrate what portions of the ODATA Filter are dynamic.<\/p>\n<pre>Status ne 'Approved' and Date gt datetime'&lt;START DATE&gt;' and Date lt datetime'&lt;END DATE&gt;'<\/pre>\n<p>To implement it, first I added a Compose Action to my Flow to create a dynamic start date and time.\u00a0 In this case, my start date is 7 days ago.<\/p>\n<p><a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1313\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate.png\" alt=\"\" width=\"902\" height=\"171\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate.png 902w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate-300x57.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate-768x146.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate-260x49.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate-50x9.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeStartDate-200x38.png 200w\" sizes=\"auto, (max-width:767px) 480px, (max-width:902px) 100vw, 902px\" \/><\/a><\/p>\n<p>Next, I added another Compose Action to my Flow to create a dynamic end date and time.\u00a0 In this case, my end date and time is the precise time the Flow executes.<\/p>\n<p><a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1314\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate.png\" alt=\"\" width=\"901\" height=\"170\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate.png 901w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate-300x57.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate-768x145.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate-260x49.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate-50x9.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/ComposeEndDate-200x38.png 200w\" sizes=\"auto, (max-width:767px) 480px, (max-width:901px) 100vw, 901px\" \/><\/a><\/p>\n<p>Finally, I created the ODATA Filter expression in the SharePoint GetItems Action and I used the Output values from the previous Compose Actions.<\/p>\n<p><a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/SPGetItems.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-1312\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/SPGetItems.png\" alt=\"\" \/><\/a><\/p>\n<p>Here\u2019s what it looks like when you bring it all together.\u00a0 Sing it, all together now\u2026\u00a0 \u201cLet it Flow, let it Flow, let it Flow!\u201d<\/p>\n<p><a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1318\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2.png\" alt=\"\" width=\"904\" height=\"1018\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2.png 904w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2-266x300.png 266w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2-768x865.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2-130x146.png 130w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2-44x50.png 44w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2017\/06\/BigPicture-2-62x70.png 62w\" sizes=\"auto, (max-width:767px) 480px, (max-width:904px) 100vw, 904px\" \/><\/a><\/p>\n<p><strong>Formatting Dates And Times<\/strong><\/p>\n<p>On a related note, if you wish to apply formatting to the date time values, here\u2019s an example of formatting the start and end dates in Compose actions.<\/p>\n<p><strong>Start Date and Time<\/strong><\/p>\n<p>Expression: <code>@adddays(utcnow(), -7, 'yyyy-MM-ddTHH:mm:ssZ')<\/code><\/p>\n<p>Example output:\u00a0 <code>2017-06-15T17:28:20Z 2017-06-08T17:28:20Z<\/code><\/p>\n<p><strong>End Date and Time<\/strong><\/p>\n<p>Expression: <code>@utcnow('yyyy-MM-ddTHH:mm:ssZ')<\/code><\/p>\n<p>Example output:\u00a0 <code>2017-06-15T17:28:20Z<\/code><\/p>\n<p>Here are some helpful links you can use to learn more about writing ODATA Filter expressions and how to format them.<\/p>\n<p>Using Filter Expressions in OData URIs<\/p>\n<p><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh169248(v=nav.90).aspx\">https:\/\/msdn.microsoft.com\/en-us\/library\/hh169248(v=nav.90).aspx<\/a><\/p>\n<p>Workflow Definition Language schema for Azure Logic Apps<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/logic-apps\/logic-apps-workflow-definition-language\">https:\/\/docs.microsoft.com\/en-us\/azure\/logic-apps\/logic-apps-workflow-definition-language<\/a><\/p>\n<p>Custom Date and Time Format Strings<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/custom-date-and-time-format-strings#the-dd-custom-format-specifier\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/custom-date-and-time-format-strings#the-dd-custom-format-specifier<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working on a project for Microsoft recently I needed to use a Microsoft Flow to return all list items from a SharePoint list that were<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":1321,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[103,120,104,97],"tags":[42,113,5,6,45,7,43],"class_list":["post-1307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud","category-flow","category-office-365","category-sharepoint","tag-cloud","tag-flow","tag-helpful-code","tag-how-to-sharepoint","tag-o365","tag-sharepoint","tag-sharepoint-online"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/comments?post=1307"}],"version-history":[{"count":3,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1307\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1307\/revisions\/1320"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media\/1321"}],"wp:attachment":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media?parent=1307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/categories?post=1307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/tags?post=1307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}