So I have this really simple function which updates a couple of fields on two different lists (one is a document library) The thing is on the document library does not updates any of the fields I need to update.
Here's the code
public void Approval(int id, string comment, bool result)
{
string ownerLibraryName = string.Empty;
string targetUserName = string.Empty;
int targetId = 0;
string userName = string.Empty;
userName = SPContext.Current.Web.CurrentUser.Name;
string userLibraryName = SPContext.Current.Web.CurrentUser.LoginName.GetUserWithOutDomain();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite noSecuritySite = new SPSite(SPContext.Current.Site.Url))
{
noSecuritySite.AllowUnsafeUpdates = true;
using (SPWeb noSecurityWeb = noSecuritySite.OpenWeb())
{
noSecuritySite.AllowUnsafeUpdates = true;
SPList userLibrary = noSecurityWeb.Lists.TryGetList(userLibraryName);
if (userLibrary == null) { throw new Exception(string.Format("La biblioteca {0} no existe", userLibraryName)); }
SPListItem voboRequest = userLibrary.GetItemById(id);
targetId = int.Parse((voboRequest[CustomSiteColumns.FIELD_VOBO_ID].ToString()));
SPFieldUserValue docOwner = new SPFieldUserValue(voboRequest.Web, voboRequest[CustomSiteColumns.FIELD_VOBO_DOC_OWNER].ToString());
ownerLibraryName = docOwner.User.LoginName.GetUserWithOutDomain();
voboRequest[CustomSiteColumns.FIELD_CURRENT_ACTION] = "MoveTo";
noSecurityWeb.AllowUnsafeUpdates = true;
SPList docOwnerLibrary = noSecurityWeb.Lists.TryGetList(ownerLibraryName);
if (docOwnerLibrary == null) { throw new Exception(string.Format("La biblioteca {0} no existe", ownerLibraryName)); }
SPListItem targetDoc = docOwnerLibrary.GetItemById(targetId);
targetDoc[CustomSiteColumns.FIELD_ARCHIVE_RESPONSE] = comment;
targetDoc[CustomSiteColumns.FIELD_ARCHIVE_APPROVAL] = result;
targetDoc.Log(string.Empty, DateTime.Now, result ? Support.Enums.TraceableOperation.Aprobado : Support.Enums.TraceableOperation.Rechazado, userName, comment);
targetDoc.Update();
voboRequest.Update();
voboRequest.Delete();
noSecurityWeb.AllowUnsafeUpdates = false;
}
noSecuritySite.AllowUnsafeUpdates = false;
}
});
}
If I check the targetDoc[CustomSiteColumns.FIELD_ARCHIVE_RESPONSE]
field after the targetDoc.Update()
, I get a null value, but if I check the voboRequest[CustomSiteColumns.FIELD_CURRENT_ACTION]
value after the voboRequest.Update()
I get a 'MoveTo', which is precisely the value I just assigned.
Any ideas what might be happening?