resultOffset parameter

1389
3
Jump to solution
05-17-2021 08:14 AM
ClémentLaskar
New Contributor III

I must be missing something :

The REST API supports a resultOffset parameter to fetch records that are beyond maxRecordCount. https://developers.arcgis.com/rest/services-reference/enterprise/query-feature-service-layer-.htm

However, I cannot find this parameter in the 4.19 API https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-OffsetParameters.ht... nor in the 3.36 API https://developers.arcgis.com/javascript/3/jsapi/query.html.

What is the way to get records with the 4.x version above maxRecordCount from my service ?

Thanks a lot

1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

Since you'll be using Query to retrieve the features, check out the properties available in this class; and related to your question the 'start' parameter: Query.start 

View solution in original post

3 Replies
BlakeTerhune
MVP Regular Contributor

This is what I did with 10.5.1 services. There's probably a better way now but I haven't revisited it. The undefined queryObject variable is your original query object.

 

// Set record limit to match the service being queried
const maxRecordCount = 1000;
// Ensure only one value for outFields (changed at 10.6.1)
// When returnCountOnly and returnDistinctValues are true,
// more than one field specified in outFields is not supported.
let queryForCount = queryObject.clone();
if (queryForCount.outFields && queryForCount.outFields.length > 1) {
  queryForCount.outFields = [queryForCount.outFields[0]];
}
let queryTask = new QueryTask({url: "urlForMyLayer"});
queryTask.executeForCount(queryForCount)
.then(function(queryRecordCount) {
  if (queryRecordCount) {
    // Build array of page steps and use to query the service
    // as many times as necessary to retrieve all records.
    const pageCount = Math.ceil(queryRecordCount / maxRecordCount);
    let resultPages = [];
    for (let i = 0; i < pageCount; i++) {
      resultPages.push(i * maxRecordCount);
    }
    return Promise.all(resultPages.map(function(resultPageStart) {
      queryObject.start = resultPageStart;
      queryObject.num = maxRecordCount;
      return queryTask.execute(queryObject);
    }));
  } else {
    // No records to query; send back an Array with one empty FeatureSet
    // to mimic the return from Promise.all()
    console.log('No records to query');
    return Promise.resolve([new FeatureSet()]);
  }
})
.then(function(featureSets) {
  // Combine all features into the first FeatureSet for return.
  let returnFeatureSet = featureSets.pop();
  featureSets.forEach(function(featureSet) {
    Array.prototype.push.apply(returnFeatureSet.features, featureSet.features);
  });
  resolve(returnFeatureSet);
})
.catch(function(err) {
  reject(err);
});

 

JohnGrayson
Esri Regular Contributor

Since you'll be using Query to retrieve the features, check out the properties available in this class; and related to your question the 'start' parameter: Query.start 

ClémentLaskar
New Contributor III

Thanks John ! Also it's quite confusing the parameters names are different from those in the REST API. I was indeed missing something !

0 Kudos