Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to get a calculated field with modify date, when one field or column changes in the share point list.

For example, If I have a field status, i should get a modify field populated with today's date whenever I change the status field. The date column should not change in case of changes in the other column other than status column.

Please help me ...

UPDATE Event Reciever code I tried..

public override void ItemUpdating(SPItemEventProperties properties)
       {

           string currentStatus = properties.ListItem["Status"].ToString();
           string newStatus = properties.AfterProperties["Status"].ToString();

           if (currentStatus != newStatus)
           {
               SPListItem oItem = properties.ListItem;
               oItem["Last Modified"] = "Hi";
               oItem.Update();
           }

       }

Element.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="120">
      <Receiver>
        <Name>EventReceiver1ItemUpdating</Name>
        <Type>ItemUpdating</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>StatChange.EventReceiver1.EventReceiver1</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>

  </Receivers>
</Elements>

ListTemplateId="120" (Because - List is of type DataSheet List).

However getting a conflict like - Rows you changed were previously changed by (My User Name) on ...... Your chnages conflict with that users change.

This I believe because of the update command in the Reciever. How can I get rid of this - Though the column 'Last Modified' is populating correctly ....

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

I think you can't update Item in ItemUpdating method, that will triger Recursion updating. As described in this question/answer: http://stackoverflow.com/questions/3065881/how-to-change-a-field-value-during-the-itemupdating-event.

So, my solution is: do it at client side. Write some JQuery code in your page to monitor the status field's value. Only when it changes, you sent your hidden "Last Modified" field value with the current date by JQuery like $("#your_field_id").attr("value",now);

You can use SharePoint Designer to customize your list's Edit Form to hide the "Last Modified" field, thus you can prevend from manually changing the date.

share|improve this answer
    
Thank you jony, however I am really bad in Jquery, any ways looks like there is no other way I can do it. Thanks for explaining this... –  Jithu Nov 15 '11 at 6:03
add comment

if you change this field through code you can try to use SPListItem.SystemUpdate method.

public override void ItemUpdating(SPItemEventProperties properties)
   {

       if (properties.BeforeProperties["Status"]!= properties.AfterProperties["Status"])
       {
           properties.AfterProperties["Modified"] = properties.BeforeProperties["Modified"];
       }

   }
share|improve this answer
    
Hi Alex, Thank you for your help. However I am using the Data Sheet Type of list. So Can I write a code when ever the user changes the content in the status column - Update Calculated list? Please help? –  Jithu Nov 11 '11 at 9:02
    
Try to add list item event receiver to your list. In this receiver you can override ItemUpdating method. In this method you can check what field is modified, if this field is status you can try to use two approachs: use 'properties.Cancel = true' to stop item updating and invoke SystemUpdate; set 'properties.AfterProperties["Modified"] = properties.BeforeProperties["Modified"]' (This should work properly). –  Alexander Nov 11 '11 at 10:32
    
Please have a look at the updated question.. –  Jithu Nov 11 '11 at 11:29
    
I have edited code in your question. But there is a small problem. If the user changes several fields and one of them is a status field, the modified field was not changed. you should check fields that can be edited by user. it is my first time when I edit question.. so I don't know when you see changes ( –  Alexander Nov 11 '11 at 11:47
    
HI Alex, I dint see any edit in the question . You can just copy the code and update in your answer. Thank you!! –  Jithu Nov 11 '11 at 11:54
show 5 more comments

I would write an event handler (SPItemEventReceiver) to do this, and then register it against my list.

share|improve this answer
    
Thank you for your suggestion, Please have a look at the updated question.. –  Jithu Nov 11 '11 at 11:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.