filtering dates in a data view webpart when using webservices datasource

Posted by Patrick Olurotimi Ige on Geeks with Blogs See other posts from Geeks with Blogs or by Patrick Olurotimi Ige
Published on Mon, 12 Nov 2012 06:22:37 GMT Indexed on 2012/11/12 11:03 UTC
Read the original article Hit count: 253

Filed under:
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.


       
       

© Geeks with Blogs or respective owner