2

I want to filter the field with data type Multi line text, but somehow am not able to filter that. I guess this didn't work as it contains html code within it, between the div tag my text appears.

Below is the filter URL

url :_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Site')/items?$select=Title,Keywords&$filter=Keywords contains 'test'"

Any help would be appreciated

3

Try it as below:

_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Site')/items?$select=Title,Keywords&$filter=substringof('test',Keywords)

If that doesnt work, you need to create a POST request 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('Site',"<View><Query><Where><Contains><FieldRef Name='Keywords'/><Value Type='Note'>test</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)); 
  });

Reference - Using CAML with REST API

  • 1
    Time we learn people Functional Programming, Gautam. Your for loop has a typo, always displays all items. In FP that typo is difficult to make; its items.forEach(function(item){console.log(item)}) Since it takes a Function (that's why its called Functional Programming.. its not magic); you could do items.forEach(console.log) that will log all 3 parameters: value, index (the i in your for loop) and the whole array items – Danny '365CSI' Engelman Feb 24 '17 at 7:45

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.