SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.24k stars 1k forks source link

PATCH REST API to update a SharePoint List Item will put a blank value to a "Multiple lines of text" field with append changes option activated #9462

Open Aymkdn opened 8 months ago

Aymkdn commented 8 months ago

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

SharePoint REST API

Developer environment

Windows

What browser(s) / client(s) have you tested

Additional environment details

Not applicable because the problem is related to how SharePoint treats the REST request.

Describe the bug / error

When a SharePoint list has "Item Version History" activated ("Create a version each time you edit an item in this list?" to "Yes"), and when there is a "Multiple lines of text" field with "Append Changes to Existing Text" set to "Yes", then if we use the REST API _api/web/lists/getbytitle('List')/items(Id) with the method PATCH to update an item, the "Multiple lines of text" field is set to a blank value.

Steps to reproduce

  1. Create a SharePoint Online list and activate the versionning image

  2. Add a "Multiple lines of text" field and use "Yes" for "Append Changes to Existing Text" image

  3. Enter a new entry, either by doing it with SharePoint UI, or REST API, or SOAP Web Service, and put a value in the "Multiple Lines of Text" field image

  4. Retrieve the item using REST API

    fetch("/sites/Demo/_api/web/lists/getbytitle('Demo')/items(1)", {
    method:"GET",
    headers:{
    "X-RequestDigest": document.querySelector("#__REQUESTDIGEST").value,
    "Accept": "application/json; odata=nometadata",
    "Content-Type": "application/json; odata=nometadata"
    }
    })

It returns the below:

{
    "FileSystemObjectType": 0,
    "Id": 1,
    "ServerRedirectedEmbedUri": null,
    "ServerRedirectedEmbedUrl": "",
    "ContentTypeId": "0x0100755C42E31349534F9937768E0577E3C60042A0B5298D818C40B6247CEA99AF66A2",
    "Title": "Demo Entry 1",
    "OData__ColorTag": null,
    "ComplianceAssetId": null,
    "Multiple_x0020_lines_x0020_of_x0": "<div class=\"ExternalClass8D972C063C914EE0982E738777F81E71\"><div style=\"font-family&#58;Calibri, Arial, Helvetica, sans-serif;font-size&#58;11pt;color&#58;rgb(0, 0, 0);\">This is a demo test to show the bug.</div></div>",
    "ID": 1,
    "Modified": "2024-01-16T10:05:15Z",
    "Created": "2024-01-16T10:05:15Z",
    "AuthorId": 6,
    "EditorId": 6,
    "OData__UIVersionString": "1.0",
    "Attachments": false,
    "GUID": "a84fc243-7bc9-4b9d-8c12-efab66396a45"
}
  1. Use REST API to update the "Title" field to a different value

    fetch("/sites/Demo/_api/web/lists/getbytitle('Demo')/items(1)", {
    method:"PATCH",
    headers:{
    "X-RequestDigest": document.querySelector("#__REQUESTDIGEST").value,
    "Accept": "application/json; odata=nometadata",
    "Content-Type": "application/json; odata=nometadata",
    "IF-MATCH":"*"
    },
    body: JSON.stringify({"Title":"Hello World"})
    })
  2. Retrieve the item using REST API

    fetch("/sites/Demo/_api/web/lists/getbytitle('Demo')/items(1)", {
    method:"GET",
    headers:{
    "X-RequestDigest": document.querySelector("#__REQUESTDIGEST").value,
    "Accept": "application/json; odata=nometadata",
    "Content-Type": "application/json; odata=nometadata"
    }
    })

It returns the below:

{
    "FileSystemObjectType": 0,
    "Id": 2,
    "ServerRedirectedEmbedUri": null,
    "ServerRedirectedEmbedUrl": "",
    "ContentTypeId": "0x0100755C42E31349534F9937768E0577E3C60042A0B5298D818C40B6247CEA99AF66A2",
    "Title": "Hello World",
    "OData__ColorTag": null,
    "ComplianceAssetId": null,
    "Multiple_x0020_lines_x0020_of_x0": null,
    "ID": 2,
    "Modified": "2024-01-16T10:07:17Z",
    "Created": "2024-01-16T10:05:15Z",
    "AuthorId": 6,
    "EditorId": 6,
    "OData__UIVersionString": "2.0",
    "Attachments": false,
    "GUID": "a84fc243-7bc9-4b9d-8c12-efab66396a45"
}

Remark: Title has been updated to "Hello World", but Multiple_x0020_lines_x0020_of_x0 has also been updated to "null"!

  1. Go to the item and check the "Version History": image

As showed above, the "Multiple lines of text with History" field received an empty value when a different field has been updated by REST API, which will cause the field to now return a blank when trying to retrieve its value.

Current work arounds:

Expected behavior

Updating a field in the item should not reset/put blank in another field.

ghost commented 8 months ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.