views:

238

answers:

1

I'm trying to duplicate a SPFieldDateTime's value into another SPFieldDateTime in an event handler and I have to admit, I'm stumped. There are no obvious fields I can set in an SPFieldDatetime and the following doesn't change my field's value:

{
   SPListItem task = (SPListItem) properties;
   task[/* destination field's guid */] = task[/* source field's guid */];
}

The code seems to be able to retrieve the fields without error. Using either of the GUIDs in SPFieldDateTime time = (SPFieldDateTime)task.Fields[/* either GUID */]; executes without error and the debugger appears to have the right field: the proper values exist in the properties etc.

How do I set a SPFieldDateTime value?

A: 

The failure in the above is that I did not call Update in this execution sequence. I did call update on the task but it is done in a privileged execution area which is isolated from the space the event handler runs in.

The fix:

{
   SPListItem task = (SPListItem) properties;
   task[/* destination field's guid */] = task[/* source field's guid */];
   task.Update();
}
antik

related questions