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

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");
       }
share|improve this question
1  
The ItemUpdating is used for validation. If you want to set the values of fields, do it in the ItemUpdated event instead. –  Ravi Suthar Aug 16 '12 at 12:48
    
indeed it works in the itemupdated –  L.V. Sharepoint Architect Aug 16 '12 at 13:09
    
just put it as an answer to give you the points –  L.V. Sharepoint Architect Aug 16 '12 at 13:22

1 Answer 1

up vote 1 down vote accepted

The ItemUpdating is used for validation. If you want to set the values of fields, do it in the ItemUpdated event instead...

share|improve this answer

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.