3

Path is a calculated field in Menu list of my sharepoint application. It concatenates two numbers into a path like below:

1/2, 1/3, 2/4, 2/2

I want to sort my List based on this field but get the below error. How can i solve this?

http://mysite/sites/siteone/_api/web/lists/GetByTitle('Menu')/items?$orderby=Path

{
    error: {
        code: "-1, Microsoft.SharePoint.SPException"
        message: {
            lang: "en-US"
            value: "The field 'Path' of type 'Calculated' cannot be used in the query sort expression."
        }
     }
}
4

I don't believe SharePoint's REST API supports ordering or filtering on calculated columns.

The workaround is to use the ListData web service, like so:

http://mysite/sites/siteone/_vti_bin/listdata.svc/Menu?$orderby='Path'

  • 2
    Are there any updates on this for Office365 sites? I still cannot filter on calculated columns using the 2013 style REST call (_api/web) – Aamir Jun 14 '16 at 17:05
  • Not that I know of. Why not just use the ListData Web service? – Submits Jun 14 '16 at 17:44
  • Thats what I am now using, i.e. ListData.svc, but was hoping if there were any updates so that I can use the _api/web and the functionality that comes with it. Oh well. – Aamir Jun 14 '16 at 19:38
0

We can't use filter or orderby on Calculated fields in this REST method like : _api/web/getbytitile or /_api/Web/lists('{ID}') in SharePoint 2013

but in 2010 we can call _vti_bin/listdata.svc but we still call it in 2013 and Microsoft still supporting that way : this article

for filter only way use this method in JavaScript or another instead of:

     var chartData = [];
    loadRequest("/_api/lists('{DDBAAAAB-AAAF-AAAD-AAAA-AAAADDDDAAAA}')/items?$orderby=order%20asc&$filter=order%20gt%200",
          function (data) {

              var listItems = data.d.results;

              for (var i = 0; i < listItems .length; i++) {
              if( Number(listItems[i].FIELDFILTER) != 0)
              {
                 ...
              }
           }
           }

for orderby only way use this method in javascript or another instead :

function dynamicSortMultiple() {
    /*
     * save the arguments object as it will be overwritten
     * note that arguments object is an array-like object
     * consisting of the names of the properties to sort by
     */
    var props = arguments;
    return function (obj1, obj2) {
        var i = 0, result = 0, numberOfProperties = props.length;
        /* try getting a different result from 0 (equal)
         * as long as we have extra properties to compare
         */
        while(result === 0 && i < numberOfProperties) {
            result = dynamicSort(props[i])(obj1, obj2);
            i++;
        }
        return result;
    }
}

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.