Monday, 16 August 2010

Show items for last 14 days

The site I've been tasked with looking after (or more precisely supporting the guy who looks after it) has a few pages that are basically reports generated via via data sources (I think they're like a 'canned query' or View (in Oracle terms) but are an ASPX item on a page rather than SQL or something sane like that).

We had a request in to amend one of these so it only shows items created in the last 14 days, the report goes to a meeting every fortnight so anything over 14 days old will have been dealt with at the last meeting. Were these regular SharePoint views, no problem. Just add a filter on the Created column for greater then of equal to [Today]-14 and we'd be fine. Unfortunately the data source interface apparently doesn't know about [Today] or doing calculations in queries. There is a parameter called [CurrentDate] which appears to return the current date (like [Today]) but it doesn't seem to work in calculations.

I did some Google searching and found a page part way there. In this case they basically put a calendar control on the page and created a filter for Created greater or equal to that. Set that 14 days in the past and it will have the same effect, but not what the user wanted.

In the end we had to work around it by putting a calculated field on the list items for Created + 14 and check that [CurrentDate] is less than or equal to that. Works but messy.

No comments:

Post a Comment