Interesting approach, thanks. My feature layer (hosted at 10.5.1) doesn't have a maxRecordCount property. It doesn't even have a capabilities property. Any thoughts on that?
After posting I got something that I think works. Besides the fact it doesn't work with returnDistinctValues (as I mentioned before), I'm not sure how I feel about it.
var maxRecordCount = 1000;
var queryTask = new QueryTask();
queryTask.url = 'http://server/arcgis/rest/services/ServiceName/MapServer/0';
var queryParams = new Query({
returnGeometry: false,
outFields: ['someFieldName'],
where: 'someFieldName is not null',
});
queryTask.executeForCount(queryParams)
.then(function(queryRecordCount) {
var pageCount = Math.ceil(queryRecordCount / maxRecordCount);
var resultPages = [];
for (var i = 0; i < pageCount; i++) {
resultPages.push(i * maxRecordCount);
}
return Promise.all(resultPages.map(function(resultPageStart){
queryParams.start = resultPageStart;
queryParams.num = maxRecordCount - 1;
return queryTask.execute(queryParams);
}))
})
.then(function(featureSets) {
var features = [];
featureSets.forEach(function(featureSet) {
features = features.concat(featureSet.features);
})
})
.catch(function(err) {
console.error(err);
});