Pages

Wednesday, May 27, 2015

Filtering SPD 2013 Workflow REST calls by Date

I recently spent way too much time trying to figure out why my REST call was failing in a SPD 2013 Workflow when I was filtering on a DateTime field.

All the articles I found relating to filtering by a DateTime seemed to hard-code a date. I.e. ...$filter=SomeDateField eq DateTime'2015-05-27T00:00:00Z'... which is fine and works but if you are filtering using DateTime variable (because you are applying some sort of date transformation) then it is difficult to find anything about how to do this.

Turns out when you add your filter date variable to the above example, you need to change the 'Return field as:' setting from "String" to "ISO Formatted".

So the above example would look something like:
...$filter=SomeDateField eq DateTime'[%Variable:FilterDate%]'... and when you add that variable you select to return the contents as ISO Formatted.

NOTE: Just incase, you cannot just type in the bit of code in the [%..%] section, you need to use the "Add or Change Lookup" button in the String Builder dialog.

Hope this saves someone else some time.