Introduction
In this article, we learn how to update a SharePoint List Item without increasing its item file version. We will be using the SharePoint REST API for this purpose.
Description
I came across one specific requirement that while updating document metadata fields like Title or Other fields, the version field should not be incremented.
If you know how SharePoint handles versioning for all document libraries, you are aware that even if you make smaller changes in updating Fields or content of the document, it increments the version of the document.
But we want a solution using the REST API. After some research, I have found the solution.
In Sharepoint Online, I have found "ValidateUpdateListItem" POST Endpoint at ListItem level.
-
- reqUrl= "https://brgrp.sharepoint.com/_api/web/Lists/GetbyTitle('Documents')/items(1)/ValidateUpdateListItem";
-
-
- body= {"formValues":[{"FieldName":"Title","FieldValue":"Single Update Title with versioning"}],bNewDocumentUpdate:true}
From the above URL, a sample request is provided and also, the payload for request is already there.
In "formValues", you can add multiple columns as well to update items.
If you do not provide bNewDocumentUpdate value it will take default value false. This field is responsible for incrementing version or not for specific list item.
A false value indicates that it will increment the version of the file and True value indicates that it will not increment the version of the file or list item.
See Full Source Code
-
- body= {"formValues":[{"FieldName":"Title","FieldValue":"Single Update Title with versioning__"}],bNewDocumentUpdate:true}
-
-
- var _payloadOptions = {
- method: "POST",
- body: undefined,
- headers: {
- credentials: "include",
- Accept: "application/json; odata=verbose",
- "Content-Type": "application/json; odata=verbose"
- }
- };
-
-
- fetch("https://brgrp.sharepoint.com/_api/contextinfo",_payloadOptions).then(r=>r.json())
- .then(r=>
- {
- _payloadOptions.headers["X-RequestDigest"]=r.d.GetContextWebInformation.FormDigestValue
-
- _payloadOptions.body=JSON.stringify(body);
-
-
- fetch("https://brgrp.sharepoint.com/_api/web/Lists/GetbyTitle('Documents')/items(1)/ValidateUpdateListItem()"
- ,_payloadOptions).then(r=>r.json()).then(r=>console.log(r))
- })