0

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");
       }
  • 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 – Luis Valencia Aug 16 '12 at 13:09
  • just put it as an answer to give you the points – Luis Valencia Aug 16 '12 at 13:22
1

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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