0

I'm trying to filter all the data using OData where the FileRef constains let's say '/sites/my_site/myfolder'for this I tried something like: $filter=substringof('/sites/my_site/myfolder', FileRef) but it seems like it doesn´t work, so I wonder if is there a way in which I can get only the records that in its FileRef property contanins some.

Thanks a lot.

1 Answer 1

2

Looks to be an issue with SharePoint.

UserVoice - Fix REST FileRef queries

However, you can use the getitems POST method along with CAML query to retrieve the items as below:

var queryText = '<Where><Contains><FieldRef Name="FileRef"/><Value Type="Url">/sites/my_site/myfolder</Value></Contains></Where>';

var viewXml = '<View><Query>' + queryText + '</Query></View>';
var webserviceUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Test')/getitems"; //replace with your list/doc lib
var queryPayload = {  
           'query' : {
                  '__metadata': { 'type': 'SP.CamlQuery' }, 
                  'ViewXml' : viewXml,
           }
};

$.ajax({
           url: webserviceUrl,
           method: "POST",
           data: JSON.stringify(queryPayload),
           headers: {
              "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
              "Accept": "application/json; odata=verbose",
              "content-type": "application/json; odata=verbose"
           },
           success:function(data){
                var results = data.d.results;
                //iterate it over the results
                 for(var i = 0; i < results.length;i++) {
                     console.log(results[i].Title);
                 } 
           },
           error:function(data){
                console.log("something went wrong");
           }
});

Using CAML with REST api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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