Updating Editor field on SharePoint Online using the CSOM with App Only Auth

Copper Contributor

I have the following issue.

 

I work with CSOM and I want to update the Author and Editor field on a List Item object. The actual problem is that the Editor is not updated and the value is set to the SharePoint App user. The problem occurs after using the App Only Authentication.

 

The following method is used to update Author, Editor, Creation Date and Modified Date.

 List<SP.ListItemFormUpdateValue> values = new List<SP.ListItemFormUpdateValue>();
                
foreach (ItemProperty property in properties)
{
   property.AddPropertyToUpdateList(ctx, item, info, values);
}

IList<SP.ListItemFormUpdateValue> results = item.ValidateUpdateListItem(values, true, string.Empty);

ctx.ExecuteQuery();

info.Log("<--// Called \'ValidateUpdateListItem\'. //-->");

// check for API-failures.
CheckErrors(results);

Do you have any ideas why this is not working for Editor but for Author-it works?

I also tried to use the Update method to edit the Author and Editor, but this is also not working for the Author field.

User user = service.Ctx.Web.EnsureUser("email address removed for privacy reasons");
ctx.Load(user);
ctx.ExecuteQuery();

FieldUserValue userValue = new FieldUserValue();
userValue.LookupId =user.Id;
item["Editor"] = userValue;
item["Author"] = userValue;
item.Update();

ctx.ExecuteQuery();

 

3 Replies

HI @cristinadulau 

 

you could try to set these fields using

item.systemUpdate()

instead of just "item.update()". The latter always creates a new version with the current user as the editor.

 

If you use the "ValidateUpdateListItem" Rest API then you have to set the "bNewDocumentUpdate” to true to perform a SystemUpdate, but i don't know how exactly you need to use that in the CSOM code above.


Best Regards,
Sven

Hi @SvenSieverding ,

 

Thank you for your response.

The signature of the ValidateUpdateListItem is the following one:

 

public IList<ListItemFormUpdateValue> ValidateUpdateListItem(IList<ListItemFormUpdateValue> formValues, bool bNewDocumentUpdate, string checkInComment);

 

When I am using it, I set the second parameter to true, but it still doesn't work. 

 

I searched for SystemUpdate, but I cannot find it on Microsoft.SharePoint.Client.ListItem class.

 

Best regards,

Cristina

Did you managed to find the solution?
In my case the code works fine on a list but it doesn't work for another list similar to the first one.

 

PS: Found the culprit. The app didn't had full control.