Update file metadata with Rest API using ValidateUpdateListItem in SharePoint on-premises
Published May 06 2020 04:11 PM 25.3K Views
Microsoft

This post is a contribution from Aaron Mio, an engineer with the SharePoint Developer Support team.

 

Lately. I came across an issue of using REST API ValidateUpdateListItem() to update listitem metadata. There’re a few blogs published on method ValidateUpdateListItem() for SharePoint Online. A few benefits of using ValidateUpdateListItem are:

  • Update list items without increasing its item version (see this blog for details).
  • Easier to update some types of metadata, like Taxonomy, People and Lookup fields (mentioned in Robert's blog).

Besides Robert's blog, Andrew’s blog also presented detailed info about how to set various types of fields with ValidateUpdateListItem().

My issue was to update Editor and Author fields for a listitem on SharePoint on-premises (SP2016 and SP 2019) without increasing item version.

Both Editor and Author are People and Group (Person) field. According above blogs, you can set the Person field, like:

"[{'Key':'i:0#.f|membership|aaron@contoso.onmicrosoft.com'}]"

This works fine with SharePoint Online users. However, it does not work with SharePoint on-premises users, although no error returned from the method.

After some testing, I found that for SharePoint on-premises users, you need to set the Persons field like below:

"[{'Key':'i:0#.w|aaron@testdomain.com'}]"

The sample below updates the Editor and Author fields on SharePoint on-premises (SP2016 and SP2019) without increasing item version.

{

      "formValues": [

            {

                  "__metadata": { "type": "SP.ListItemFormUpdateValue" },

                  "FieldName": "Editor",

                  "FieldValue": "[{'Key':'i:0#.w|aaron@testdomain.com'}]"

            },

            {

                  "__metadata": { "type": "SP.ListItemFormUpdateValue" },

                  "FieldName": "Author",

                  "FieldValue": "[{'Key':'i:0#.w|aaron@testdomain.com'}]"

            }

      ],

      "bNewDocumentUpdate": true

}

 

The REST API ValidateUpdateListItem() on the ListItem object is much easier in providing the Person field values to update. In addition, it has an option bNewDocumentUpdate to specify how you want item version to be updated.

1 Comment
Version history
Last update:
‎Aug 27 2020 03:39 PM
Updated by: