2

I am trying to set the property ReadOnlyField to false on a column using the REST API. I am trying to do this using Postman in chrome and not able to get this to work.

The Microsoft API lists how to do this using ajax:

$.ajax({
 url: "http://<site url>/_api/web/lists(guid'da58632f-faf0-4a78-8219-99c307747741')
/fields('1d22ea11-1e32-424e-89ab-9fedbadb6ce1')
/setshowindisplayform(false)",
 type: "POST",
 headers: { "X-RequestDigest": <form digest value> },
 success: successHandler,
 error: errorHandler

});

so at first I tried retrieving the value of the field using the following url and that worked (fake SP name):

GET https://example.companyname.com/EmpPic/_api/web/lists(guid'XXX-XXX')/Fields(guid'XXX-XXX')
Headers: Accept: application/json;odata=verbose

RESULT:
{
    "d": {
    "ReadOnlyField": true
    }
}

The next step was to get the FormDigest for the POST. Here is what that looks like:

POST https://example.companyname.com/EmpPic/_api/contextinfo
Headers: Accept: application/json;odata=verbose

I got back the FormDigest and now performed the POST to set the field property:

POST https://example.companyname.com/EmpPic/_api/web/lists(guid'XXX-XXX')/Fields(guid'XXX-XXX')/ReadOnlyField(false)
Headers: X-RequestDigest: 0xE80E234234....
         Accept: application/json; odata=verbose

RESULT:
{
    "error": {
        "code": "-1, Microsoft.SharePoint.Client.ResourceNotFoundException",
        "message": {
            "lang": "en-US",
            "value": "Cannot find resource for the request ReadOnlyField."
        }
    }
}

Anyone know why I am getting the error "Cannot find resource for the request ReadOnlyField"?

I've tried this: .../Fields(guid'XXX-XXX')/ReadOnlyField(False)

and the error I got was:

"The expression \"web/lists(guid'XXX-XXX')/Fields(guid'XXX-XXX')/ReadOnlyField(False)\" is not valid.
0

I wasn't able to get the REST api to work. However, I am doing this code in C#, so decided to try the client object model (CSOM). I used the following documentation:

Microsoft Client Object Model Documentation

and wrote the following code:

        ClientContext context = new ClientContext(DefaultValues.SiteUrl);

        List list = context.Web.Lists.GetByTitle(pictureLibrary);
        Field field = list.Fields.GetByInternalNameOrTitle("Picture Status");
        field.ReadOnlyField = IsReadOnlyField;

        field.UpdateAndPushChanges(true);
        context.ExecuteQuery();

Worked like a charm and required a lot less code and work. Thanks!

0

For examples on using the REST API, see https://msdn.microsoft.com/en-us/library/office/dn600182.aspx.

I was able to successful use the API to set the ClientSideComponentId property of a field in SharePoint Online using the REST API as follows:

POST to [path to site]/_api/web/lists/getbytitle('[my list title]')/Field(guid'[my field guid]') Headers:

  • Accept: application/json;odata=verbose
  • Content-type: application/json;odata=verbose
  • odata-version: '' [yes, blank]
  • Origin: https://mytenant.sharepoint.com
  • X-RequestDigest: [a current request digest]
  • X-HTTP-Method: MERGE

Body: {'__metadata':{'type':'SP.FieldLookup'},'ClientSideComponentId': '[my client side component guid]'}

I found hints at the possibility of doing this in https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/building-simple-field-customizer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.