Domanda

Here is the code I have to record the date when the workflow status on an item has been updated/changed. I created accustom column named Completed Date as a Date type in the list to display the date.

The workflow deploys fine but does not render any data under the Completed Date Column. Am I missing something?

namespace WorkflowDateRecorder.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
   /// <summary>
   /// An item is being updated.
   /// </summary>
   public override void ItemUpdating(SPItemEventProperties properties)
   {
       base.ItemUpdating(properties);
       if (properties.BeforeProperties["Wokflowstatus"] != properties.AfterProperties["Wokflowstatus"])
       {
           properties.ListItem["Completed Date"] = DateTime.Now;
           properties.ListItem.Update();
           properties.Web.Update();
       }
   }


}

}

È stato utile?

Soluzione

In ItemUpdating method, you should be setting your new field value using

properties.AfterProperties[Completed_x0020_Date] = newFieldValue;
//AfterProperties and BeforeProperties are using internal names of columns.

Also question is then, if your if statement is ever visited? Cause calling ListItem.Update() most probably would result in recursive call on this event receiver.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top