filtering dates in a data view webpart when using webservices datasource

I was working on a data view web part recently and i had  to filter the data based on dates.
Since the data source was web services i couldn't use  the Offset which i blogged about earlier.

When using web services to pull data in sharepoint designer you would have to use xpath.
So for example this is the soap that populates the rows

<xsl:variable name="Rows" select="/soap:Envelope/soap:Body/ddw1:GetListItemsResponse/ddw1:GetListItemsResult/ddw1:listitems/rs:data/z:row/>

But you would need to add some predicate [] and filter the date nodes.
So you can do something like this (marked in red)

<xsl:variable name="Rows" select="/soap:Envelope/soap:Body/ddw1:GetListItemsResponse/ddw1:GetListItemsResult/ddw1:listitems/rs:data/z:row[ddwrt:FormatDateTime(string(@ows_Created),1033,'yyyyMMdd') &gt;= ddwrt:FormatDateTime(string(substring-after($fd,'#')),1033,'yyyyMMdd')]"/>

For the filtering to work you need to have the date formatted  above as yyyyMMdd.
One more thing you must have noticed is the $fd variable.
This variable is created by me creating a calculated column in the list so something like this [Created]-2

So basically that the xpath is doing is get me data only when the Created date  is greater than or equal to the Created date -2 which is 2 date less than the created date.

Also not that when using web services in sharepoint designer and try to use the default filtering you won't get to see greater tha or less than in the option list comparison.:(

Hope this helps.


Print | posted on Sunday, November 11, 2012 6:22 PM


No comments posted yet.

Your comment:


Copyright © Patrick.O. Ige

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski