Tuesday, June 23, 2009

Using Today field in SharePoint list views

One of the coolest things about SharePoint lists is that you can filter the items in a list to such values as [Today] and [Me]. There are many posts out there of people trying to display items from this week or this month. You can do this by using the Today field in a calculated column. This blog details how to do that. The issue that you will run into is that the Today value does not update unless you edit the list item.



I worked around this by creating a simple console application that is set up as a scheduled task on the SharePoint server. The application opens up the list and loops through the list items and calls item.Update() on each one. This causes the date modified date to update and it updates the Today reference.



I have successfully used this to maintain current month views on a list. If anyone knows of another way to keep the today value updated without running a separate application, let me know.

2 comments:

  1. re: Updating a list to keep the [Today] trick reference up to date.

    There are two approaches I've seen - one like yours where you update all items the other modifies a column in a list to force all items to be recalculated (basically the same as adding/removing the fake [Today] column). Dessie talks more about the options here http://vspug.com/dez/2008/07/31/dynamically-updating-a-sharepoint-calculated-column-containing-a-quot-today-quot-reference/

    Re: Filtering items for the current calendar month/week you can do that without using the Today trick.

    http://blog.pentalogic.net/2009/11/howto-filter-items-current-calendar-month-view-sharepoint/

    ReplyDelete
  2. Here is my workaround for no-programmers:

    First of all, sorry about my poor english.

    I spent days looking for a solution for "Today" issue. I don't know anything about programming, I am system admin so It was kind of hard.

    So this is my workaround to solve it using the dumb column "today" and the fantastic extra functions for stsadm.


    1.- Download wsp for custom properties of stsadm
    http://stsadm.blogspot.com/

    2.- In any list create field "Today" manually

    3.- Export field "Today" into a xml file:

    stsadm –o gl-exportlistfield -url ""http://server/site1/SourceList/AllItems.aspx" -fielddisplayname "Today" -outputfile "c:\Today.xml"


    4.- Import and delete column "Today" into your site. It will update your values

    stsadm -o gl-importlistfield -url "http://server/site1/List1/AllItems.aspx" -inputfile "c:\TodayCol.xml"

    stsadm -o gl-deletelistfield -url "http://server/site1/List1/AllItems.aspx" -fielddisplayname "Today"

    5.- Create BAT file with the point 4 and schedule it to run once on weekdays.


    PS: In case you don't know how work with BAT files:
    run CMD

    then run this commands:
    ___________________________________
    cd\
    cd:

    copy con refreshToday.bat

    Echo. Refresh column today

    stsadm -o gl-importlistfield -url "http://server/site1/List1/AllItems.aspx" -inputfile "c:\TodayCol.xml"

    stsadm -o gl-deletelistfield -url "http://server/site1/List1/AllItems.aspx" -fielddisplayname "Today"

    (Ctrl +Z)

    schtasks /create /tn "Refresh Today" /tr c:\refreshToday.bat /sc daily /mo 24 /st 01:00:00 /sd 12/15/2009

    exit
    ___________________________________

    ReplyDelete