Forum Discussion

dzorzi's avatar
dzorzi
Copper Contributor
Jul 05, 2022

CSOM SystemUpdate() cannot update Editor field

In a SharePoint Online Document Library I've a file that is in published status (version x.0).

I am updating various fields of this file with the listItem.SystemUpdate() command.

I need this sort of update because is the only one that can be used on a published file that not increase the version. (UpdateOverrideVersion return an error on published documents)

 

When I try to update the Editor fields this is not updated.

(_currentItem is a File object)

var user = _ctx.Web.EnsureUser(publishinfo.currentUser_email);
_ctx.Load(user);
_ctx.ExecuteQuery();
_currentItem.ListItemAllFields["Editor"] = user;
_currentItem.ListItemAllFields.SystemUpdate();
_ctx.ExecuteQuery();

 

All other fields of the item can be updated. "Editor" and "Modified" are the only two that are not working. (Author for example is correctly updated in this way)

Any idea?

 

Thanks 

1 Reply

  • FabioO365GoD's avatar
    FabioO365GoD
    Copper Contributor

    dzorzi 
    Hi, you should use

    SP.FieldUserValue.fromUser('i:0#.f|membership|email address removed for privacy reasons')

     

    you have to get the LoginName from the user

     

    Example

    var context = SP.ClientContext.get_current();
    var list = context.get_web().get_lists().getByTitle(listTitle);
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var listItem = list.addItem(itemCreateInfo);
    listItem.set_item("Title", "Item Test User");
    listItem.set_item("Author", SP.FieldUserValue.fromUser("i:0#.f|membership|email address removed for privacy reasons"));

    listItem.update();
    context.executeQueryAsync(
      function () {
        console.log("Request has been created");
      },
      function logError(sender, args) {
        console.log(args.get_message());
      }
    );
     
    Thanks

Resources