5

Is there a limit on the number/size of results returned? For example, I queried for all defects and got 185 back, when the real number is above 600. Is there a way I can detect if the query couldn't get all the results?

Edit: It looks like I'm hitting the page limit size of 200. Does anyone know how to craft a loop to get the next set of results?

Here is my code:

    String rallyProjectOid = getRallyProjectOid(rallyApi, rallyProjectName);
    // Get the list of Rally defects for the project
    QueryRequest defectRequest = new QueryRequest("defect");
    defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId", "SubmittedBy", "Owner"));
    defectRequest.setProject(rallyProjectOid);
    defectRequest.setQueryFilter(new QueryFilter("LastUpdateDate", ">", timestamp));
    QueryResponse projectDefects = rallyApi.query(defectRequest);
edwin.greene
  • 139
  • 3
  • 9
  • In the example here they set a page size and limit. Possibly you are being limited by default values? http://developer.rallydev.com/help/java-toolkit-rally-rest-api From the Javadoc it does seem like the default values are 200 and 1 page though. – Dan Oct 17 '12 at 21:29
  • That helps alot Dan. It looks like 200 is the max page size, and debugging my code, that's the size of the JsonArray that's being returned. – edwin.greene Oct 17 '12 at 21:52
  • It looks like you have to do several queries to get all results each time increasing the .setStart(int). I might be mistaken there though. – Dan Oct 17 '12 at 21:58
  • What does `projectDefects.getTotalResultSize()` give you? 200 as well? – Dan Oct 17 '12 at 22:04
  • It gives 600 something. Ya that was the key factor to determining if the results were limited by the page size. – edwin.greene Oct 18 '12 at 20:53

3 Answers3

4

Although setting :

queryRequest.setLimit(Integer.MAX_VALUE);

does take care of many types, it does not work for all types.

For example, types Defect and Iteration seem to return thousands of results in a single page (a single query call to Rally), while other types such as User and HierarchicalRequirement ignored that limit, and instead, forced me to use pagination (setting the Start and then a requery) to get all the results.

Here's an example of how I handle both :

// NOTE : no pagination needed for defect or iteration, but required for hierarchicalrequirement or user
QueryRequest queryRequest = new QueryRequest("hierarchicalrequirement");

queryRequest.setFetch(new Fetch(new String[] {"ObjectID", "CreationDate", "LastUpdateDate", "FormattedId"}));
queryRequest.setQueryFilter(new QueryFilter("CreationDate", ">=", "2013-01-01T07:00:00.000Z"));
queryRequest.setLimit(Integer.MAX_VALUE);

int responseTotalResultsCount = Integer.MAX_VALUE;// So we enter while loop first time
int actualResultsProcessedSoFar = 0;

// Handle both cases
while ((queryRequest.getStart()) < responseTotalResultsCount && actualResultsProcessedSoFar < responseTotalResultsCount) {

    QueryResponse queryResponse = restApi.query(queryRequest);

    responseTotalResultsCount = queryResponse.getTotalResultCount();// Set to correct value here

    JsonArray results = queryResponse.getResults();

    if (results.size() == 0) {
        return;
    } else {

        for (JsonElement jsonElement : queryResponse.getResults()) {

            // Process this particular JsonElement here

            // If no pagination required, this counter lets us exit while loop
            actualResultsProcessedSoFar++;

        }// end for loop

    }// end if (results.size() == 0)

    // Setting this to handle pagination, if required
    queryRequest.setStart(queryRequest.getStart() + queryRequest.getPageSize());

} // end while loop
rrudland
  • 410
  • 3
  • 8
  • It should not be type dependent- it should handle all paging the same. If you are seeing incorrect behavior for stories please report this to Rally support so we can file a defect and track this issue. – Kyle Morse Apr 12 '13 at 00:29
2

There is a setLimit() method on QueryRequest that allows you set the maximum number of records to be returned from the request. If this value is not specified for the request object, the behavior will be to return only one page of data (200 records).

So if you do:

   int queryLimit = 4000;
   defectRequest.setLimit(queryLimit);

The RestApi should return a larger number of results, and page them for you automatically.

0

As of 2019, they limit it to 2000 results, doesn't matter how much you set the limit. No documentation on this. I found this by testing and setting pages and to max numbers.

This applies to Java API.

knt5784
  • 129
  • 1
  • 2
  • 16