1

I have a query that I believe I am setting up correctly, but maybe I'm missing a vital property. Does the where clause need to be set? I want to query all features, not a subset of them, so I don't really need a where restriction.

Every time I run this query it goes to the error callback where the message given is unhelpful.

printQLyr = new QueryTask("https://xxx/MapServer/3");
printQuery = new Query();
printQuery.returnGeometry = false;
printQuery.outFields = ["Name"];
printQLyr.on("complete", printQResults);
printQLyr.on("error", errorResults);
printQLyr.execute(printQuery);

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

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

What I get back in the console is this:

Error at Object.A.m.load (https://js.arcgis.com/3.24/init.js:1028:392) at https://js.arcgis.com/3.24/init.js:87:429 at c (https://js.arcgis.com/3.24/init.js:103:393) at d (https://js.arcgis.com/3.24/init.js:103:182) at b.Deferred.resolve.callback (https://js.arcgis.com/3.24/init.js:105:10) at c (https://js.arcgis.com/3.24/init.js:104:96) at d (https://js.arcgis.com/3.24/init.js:103:182) at b.Deferred.resolve.callback (https://js.arcgis.com/3.24/init.js:105:10) at https://js.arcgis.com/3.24/init.js:92:118 at h (https://js.arcgis.com/3.24/init.js:107:277)

  • Are the ObjectID and Shape fields accessible in your service? Can you run a query on the service page itself? – kenbuja Jun 20 '18 at 16:32
  • @kenbuja Yes, I can run a query on the service page. I can even run the query from my JS web application if I include printQuery.where and set it to something, but since I want to query all features, it doesn't make sense to set the where clause. I also see OBJECTID and Shape listed as fields under the "Fields" heading on my rest services page for the service, so I believe that means they're accessible. – MKF Jun 20 '18 at 16:43
  • @kenbuja It also runs fine if I set the printQuery.objectIds property... It just doesn't work when I have no filters set. I have also just tested this code snippet in the ArcGIS JS Sandbox and I receive the same error there as well. – MKF Jun 20 '18 at 17:08
  • 2
    The sample in the documentation have either a geometry or some type of where clause. Try using printQLyr.where "1=1" – kenbuja Jun 20 '18 at 17:40
  • @kenbuja That worked! Thank you! Add it as an answer and I'll mark it correct. – MKF Jun 20 '18 at 17:45
2

A Query will need a geometry, objectId, or a where clause to run. To select all features, use

printQLyr.where="1=1";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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