locked
automatic list update RRS feed

  • Question

  • we are using calculated columns in lists to show status of list items based on date entries relative to the current date ([Today]). the issue we have is the status 'field' apparently only updates when you edit an item. is there a way to automatically edit all the rows of a column on a periodic basis? something basic like increment the value in the row by 1?
    Wednesday, January 2, 2013 7:59 PM

Answers

  • Calculated columns/fields will only update when you create/edit an item because that's when the calculation is performed. It sounds like you need some dynamic information. Can you explain more about the requirement? Perhaps, there's an alternative approach.


    Pman
    http://www.pmansLab.com/

    Thursday, January 3, 2013 2:13 AM
  • Hi shudnall,

    This is default behavior because calculate column works when you add/update item in list. If you want to update that field automatically on some time interval then you will have to create small console application which could be run through windows task scheduler or you can also create sharepoint custom timer job.

    See this sample code:

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
    using (SPSite site = "site url")             
    {              
      using (SPWeb web = site.OpenWeb())
    {   
      SPList list = web.Lists[ListName];                    
      SPQuery qry = new SPQuery();
       //use SP query to update only few items based on yoru query
       qry.Query= "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>hi</Value></Eq></Where>";
       SPListItemCollection items = list.GetItems(qry);  
       foreach (SPListItem item in items)
       {
       item["calculate column name"] = "new value";
       item.Update();
    }}}});

    Hope it could help


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Thursday, January 3, 2013 10:46 AM
    Moderator

All replies

  • Calculated columns/fields will only update when you create/edit an item because that's when the calculation is performed. It sounds like you need some dynamic information. Can you explain more about the requirement? Perhaps, there's an alternative approach.


    Pman
    http://www.pmansLab.com/

    Thursday, January 3, 2013 2:13 AM
  • Hi shudnall,

    This is default behavior because calculate column works when you add/update item in list. If you want to update that field automatically on some time interval then you will have to create small console application which could be run through windows task scheduler or you can also create sharepoint custom timer job.

    See this sample code:

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
    using (SPSite site = "site url")             
    {              
      using (SPWeb web = site.OpenWeb())
    {   
      SPList list = web.Lists[ListName];                    
      SPQuery qry = new SPQuery();
       //use SP query to update only few items based on yoru query
       qry.Query= "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>hi</Value></Eq></Where>";
       SPListItemCollection items = list.GetItems(qry);  
       foreach (SPListItem item in items)
       {
       item["calculate column name"] = "new value";
       item.Update();
    }}}});

    Hope it could help


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Thursday, January 3, 2013 10:46 AM
    Moderator