Strange error trying to run Query Task

848
2
Jump to solution
06-20-2018 10:30 AM
MKF62
by
Occasional Contributor III

I have been attempting to query all features in a layer and just return one field. Is this allowed? I cannot get it to work with any of my map services, but examples I have looked at in the API reference documentation do not always specify where clauses or objectIds to query, so that leads me to think it's allowed.

I am trying to run this snippet, but every time I run it, it goes to the errorResults function:

var printQLyr = new QueryTask("https://www.xxxxxx.org/xxxxxx/rest/services/HBM/HBD/MapServer/3");
printQuery = new Query();
printQuery.outFields = ["Name"];
printQLyr.execute(printQuery, printQResults, errorResults);

function printQResults(featureSet) {
    var resultFeatures = featureSet.features;
    console.log(resultFeatures[0]);
}

function errorResults(message) {
    console.log(message);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is the error message I receive (entirely unhelpful):

Error
    at Object.A.m.load (init.js:1028)
    at init.js:87
    at c (init.js:103)
    at d (init.js:103)
    at b.Deferred.resolve.callback (init.js:105)
    at c (init.js:104)
    at d (init.js:103)
    at b.Deferred.resolve.callback (init.js:105)
    at init.js:92
    at h (init.js:107)‍‍‍‍‍‍‍‍‍‍‍

Even when I run this in the ArcGIS JS sandbox, I receive this error. I receive this same error for any map service I try (I change the outField when I change the map service so I know that's not causing an error). 

Additionally, if I add either a line like 

printQuery.where = "StateID = 'VA'";

or

printQuery.objectIds = [1];

The query will run perfectly fine and return the records.

I can run the query in the REST API as long as I specify something in the "where" box or the "objectIds" box. If I specify nothing but an outField it will not return anything but I do not get an error message either.

How do I query all features in a dataset?

Feature layer settings:

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Molly,

   A Query does need a where or a geometry or an objectId. If you want all the records then just use where = "1=1";

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Molly,

   A Query does need a where or a geometry or an objectId. If you want all the records then just use where = "1=1";

MKF62
by
Occasional Contributor III

You always come through for me Robert. Thanks a lot.

0 Kudos