Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an AJAX call querying the SharePoint REST API which will return more than 500 rows:

$.ajax(
        {
             url: _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='Department:"
                    + "*'&selectproperties='Department'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'&sortlist='Department:ascending'&rowlimit=500",
                method: "GET",
                headers: {
                    "accept": "application/xml",
                },
                success: onSuccess,
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(thrownError);
                }
            }
        );

The REST API has a 500 row limit, so I cannot increase the rowlimit variable in the url.

In my onSuccess function, I'm trying to read the total rows to see if I need to query again for more rows:

onSuccess = function (data) {
    var rows = data.d.postquery.PrimaryQueryResult.RelevantResults.TotalRows;
....

This throws an exception that postquery does not exist, however.

How can I grab the TotalRows and query the REST API for additional rows?

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

See if these paths to the row count variables work:

data.d.query.PrimaryQueryResult.RelevantResults.RowCount

data.d.query.PrimaryQueryResult.RelevantResults.TotalRows

If you have specific questions about the object model, I find that the best first point of reference is to look at the returned xml or json using web developer tools and looking at the returned object graph.

share|improve this answer
    
Both of these throw an error saying query is not defined. If I change the response type to application/json, both of those DO work... RowCount gives me 500, the total rows in the current response, not the total rows for the query, TotalRows does give me that though (again, with the json response, not the xml). I don't want the response in json though. –  tnw Feb 18 at 18:03
    
@FalakMahmood Not sure what you mean. That resides under the query object and that's not defined under the XML response. TotalRows already gives me what I want, but only with a json response. –  tnw Feb 18 at 18:10
1  
I don't have access to a 2013 farm for testing at the moment, but if you use the web developer tools in IE or Chrome, you can see the response and get an idea of the object model. –  tyshock Feb 18 at 18:21
    
@tyshock Brilliant! I totally forgot about that, I can see the TotalRows property hiding in the XML. If you'd like to add that to your answer, I will accept it. –  tnw Feb 18 at 18:38
2  
For re-querying starting from the 500th row, you can use the startrow parameter. Eg: /_api/search/query?querytext='*'&startrow=500' –  Vardhaman Deshpande Feb 18 at 19:00
show 2 more comments

You can raise the MaxRowLimit property of your Search service application (Only with On-Prem SharePoint installation) using PowerShell to overcome this limitation. But remember, it will affect the perform though.

share|improve this answer
add comment

Try these.

data.d.query.PrimaryQueryResult.RelevantResults.TotalRows

data.d.query.PrimaryQueryResult.RelevantResults.TotalRowsIncludingDuplicates

I tested on O365.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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