I need to set the current user in a field that is User Lookup. I have the following code which works fine for the datetime field but not for the user. It does not return any error, but when I try to edit the document properties again the user was not saved.
public override void ItemUpdating(SPItemEventProperties properties)
{
Logger.LogDebug("IncomingDocumentListEvents", "ItemUpdating(SPItemEventProperties properties)", "BEGIN");
string contentTypeName = properties.ListItem.ContentType.Name;
if (contentTypeName == Subsidies.Common.Constants.CONTENTTYPES_BANKCERTIFICATE_NAME)
{
base.ItemUpdating(properties);
try
{
base.EventFiringEnabled = false;
SPItemEventDataCollection afterProperties = properties.AfterProperties;
SPListItem item = properties.ListItem;
if (item != null)
{
string listName = item.ParentList.RootFolder.Name;
string approvedStatus = item.GetTaxonomyFieldValueByLanguage(item.Web.Site, Subsidies.Common.Constants.FIELDS_INCOMINGODOCUMENTSTATUS_NAME, 1043);
if (approvedStatus == Subsidies.Common.Constants.FIELDS_INCOMINGODOCUMENTAPPROVEDSTATUS_NAME)
{
SPUser user = item.Web.SiteUsers[item.Web.CurrentUser.LoginName];
afterProperties[Subsidies.Common.Constants.FIELDS_ACCOUNTINGAUDITORNAME_NAME] = user;
afterProperties.SetAfterPropertyValue(Subsidies.Common.Constants.FIELDS_APPROVALDATE_NAME, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"));
}
}
}
catch (Exception ex)
{
Logger.LogError("IncomingDocumentListEvents", "ItemUpdating(SPItemEventProperties properties)", ex);
properties.ErrorMessage = "";
properties.Cancel = true;
}
finally
{
base.EventFiringEnabled = true;
}
}
Logger.LogDebug("AgendaPointsProposedEvents", "ItemUpdated(SPItemEventProperties properties)", "END");
}