2

I have an query:

_api/web/lists/GetByTitle(<LIST_TITLE>)/items?$filter=substringof('fddffd',richTextColumn)

And it doesn't work. This error occurs:

The field 'text' of type 'Note' cannot be used in the query filter expression.

Is possible to filter by rich text column with REST API?

5

Apologies for previously erroneous and misleading answer

This is known issue. You cant filter data on rich text fields using $filter. It is present on 2013 On Premise and SharePoint online as well.

Doesnt matter if its plain text or enhanced rich text, this is unfortunately not allowed. I believe it could be for performance reasons.

So you need to use it conjunction with CAML query and make POST request to the SharePoint list.

The work around is to use is as below:

function postJson(endpointUrl,payload,success,failure)
{
    $.ajax({
      type: "POST", 
      headers: { 
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
      }, 
      data: JSON.stringify(payload),
      url: endpointUrl, 
      success: success,
      failure: failure 
   });
}

function getListItems(listTitle, queryViewXml,success,failure)
{
   var queryPayload = { 
       'query':{ 
           '__metadata': { 'type': 'SP.CamlQuery' },
           'ViewXml': queryViewXml
        } 
   }; 
   var endpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
   postJson(endpointUrl,queryPayload,
     function(data){
        success(data.d.results);    
     },failure);
}

How to use it:

getListItems('Test',"<View><Query><Where><Contains><FieldRef Name='richTextColumn'/><Value Type='Note'>fddffd</Value></Contains></Where></Query></View>",
  function(items){       
      for(var i = 0; i < items.length; i++) {
          console.log(items);   
      }
  },
  function(error){
     console.log(JSON.stringify(error)); 
  });

This works in both SP2013 and Online. Have tested this multiple times on both environments.

Sorry again for not giving a proper answer previously.

Reference - Using CAML with REST API

0

It is limitation in SharePoint REST API. There is work around for same is POST request or CAML query.

Please see below reference link for filter using richtext column.

Reference Link : REST API Limitations On Premise and Workarounds

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.