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)

Ian Turton
84.1k6 gold badges93 silver badges190 bronze badges
asked Jun 20, 2018 at 16:17
5
  • Are the ObjectID and Shape fields accessible in your service? Can you run a query on the service page itself? Commented Jun 20, 2018 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. Commented Jun 20, 2018 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. Commented Jun 20, 2018 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" Commented Jun 20, 2018 at 17:40
  • @kenbuja That worked! Thank you! Add it as an answer and I'll mark it correct. Commented Jun 20, 2018 at 17:45

1 Answer 1

2

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

printQLyr.where="1=1";
answered Jun 20, 2018 at 17:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.