I am trying to filter a rest query but can't seem to get it to work.

During my testing, the following statement works (no filter, a alternate way to get the item I wanted):

// sort the list desc and grab the top item
var url = "../_vti_bin/listdata.svc/ProjectStatusReport?$orderby=PeriodEndDate desc&$top=1&$expand=RiskHealth,ScopeHealth,ScheduleHealth,CostHealth,ProjectStage";

This one, with a filter, doesn't work:

// grab an item by the report ID
var url = "../_vti_bin/listdata.svc/ProjectStatusReport?$filter=ReportId+eq+'1'&$expand=RiskHealth,ScopeHealth,ScheduleHealth,CostHealth,ProjectStage";

I tried these too:

var url = "../_vti_bin/listdata.svc/ProjectStatusReport?$filter=ReportId eq '1'&$expand=RiskHealth,ScopeHealth,ScheduleHealth,CostHealth,ProjectStage";
var url = "../_vti_bin/listdata.svc/ProjectStatusReport?$filter=(ReportId eq '1')&$expand=RiskHealth,ScopeHealth,ScheduleHealth,CostHealth,ProjectStage";

When I use the filtered version I get the following results:

$.getJSON(url, function (data) {
    alert(data);                        // returns [object Object]
    alert(data.d);                      // returns [object Object]
    alert(data.d[0]);                   // returns undefined
    alert(data.d.results);              // returns undefined
    alert(JSONdata.stringify(data.d));  // alert doesn't fire
    alert(JSONdata.stringify(data));    // alert doesn't fire

Any help is appreciated

Edit: I did test all three in the browser address bar and they all work


Try to remove quotes from field value in your url.

var url = "../_vti_bin/listdata.svc/ProjectStatusReport?$filter=ReportId+eq+1&$expand=RiskHealth,ScopeHealth,ScheduleHealth,CostHealth,ProjectStage";

OK, it turns out I should have been using:


instead of


to access the data in the json string. I forgot "results" is only used when you use $top.

I still don't understand why JSON.Stringify was not returning anything even when the values obviously had an object: [object Object]

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.