Make a field ReadOnly in SharePoint List

We can make a field readonly or editable in SharePoint using REST API. I usually use it when I want to update a bunch of SharePoint List Items without changing their Modified date and Editor details. Below is an example to make “Editor” readonly again (you’ll first need to get the Digest Token):

fetch(`${siteUrl}/_api/web/lists/getByTitle('${listName}')/fields/getbyinternalnameortitle('Editor')`, {
    method: "POST",
    headers: {
      "Accept": "application/json;odata=verbose",
      "Content-Type": "application/json;odata=verbose",
      "X-HTTP-Method": "MERGE",
      "IF-MATCH": "*",
      "X-RequestDigest": requestDigest
    },
    body: JSON.stringify({
      "__metadata": { "type": "SP.FieldUser" },
      "ReadOnlyField": true
    })
  });

This method works even if the list has more than 5,000 items.

To verify if a field is readonly or not, we can simply use the endpoint `${siteUrl}/_api/web/lists/getByTitle('${listName}')/fields/getbyinternalnameortitle('Editor')?$select=ReadOnlyField`

Leave a Reply

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

*