Update file metadata with Rest API using ValidateUpdateListItem in SharePoint on-premises

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.