Query and QueryTask Not Returning Results ... Error In Syntax?

284
14
Jump to solution
10-03-2018 10:31 AM
JohnRichardson
New Contributor III
var layerURL = "http://172.20.25.165:6080/arcgis/rest/services/Crime2018/FeatureServer/";            //querys the crimes layer for all burglaries
      var burgresultsLayer = new GraphicsLayer();

            var burgQsym = {                                       //creates the symbol for burglaries query
            type: "simple-marker",
            color: "green",
            style: "triangle",
            size: 8
      };
      /*alert(layerURL);*/
      var qTask = new QueryTask({url : layerURL});
      var burgQuery = new Query();
      burgQuery.returnGeometry = true;
      var fieldBoys = burgQuery.outFields = ["Offense", "Location"];
      /*alert(fieldBoys);*/
      burgQuery.where = "Offense = Burglary";
      qTask.execute(burgQuery).then(function(results) {
            console.log(results.features);
      });
      qTask.executeForCount(burgQuery).then(function(results) {
            console.log(results);
      });
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

  That is definitely your issue.

require([
      "esri/Map",
      "esri/views/MapView",
      "esri/widgets/Home",
      "esri/widgets/Search",
      "esri/widgets/BasemapGallery",
      "esri/widgets/Expand",
      "esri/layers/FeatureLayer",
      "esri/layers/ImageryLayer",
      "esri/widgets/LayerList",
      "esri/tasks/QueryTask",
      "esri/tasks/support/Query",
      "esri/layers/GraphicsLayer",
      "dojo/dom",
      "dojo/on",
      "dojo/domReady!"

      ],function(
      Map, MapView, Home, Search, BasemapGallery, Expand, FeatureLayer, ImageryLayer,
      LayerList, QueryTask, Query, GraphicsLayer, dom, on) {

Here is your order fixed

View solution in original post

14 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

  Your where clause is wrong:

burgQuery.where = "Offense = 'Burglary'";
0 Kudos
JohnRichardson
New Contributor III

Thank you ... I edited that code and still no go!

Getting this in console:

dojo.js:19 Uncaught TypeError: qTask.execute is not a function at Map.js:142 at K (dojo.js:18) at dojo.js:19 at E (dojo.js:19) at da (dojo.js:19) at e (dojo.js:21) at HTMLScriptElement.<anonymous> (dojo.js:23)
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

  OK I did not notice before that your url does not contain a specific layer id at the end of it which is required.

0 Kudos
JohnRichardson
New Contributor III

Thank you Robert ... I had noticed that after I posted this code ... 

It now reads :

var layerURL = "http://172.20.25.165:6080/arcgis/rest/services/Crime2018/FeatureServer/0";  

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

   If it works now. Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos
JohnRichardson
New Contributor III

Not working yet ... thanks for your help!

I will most definitely mark as correct when time comes.

Thanks again.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

So what is the error you are getting now then?

0 Kudos
JohnRichardson
New Contributor III

Same one

dojo.js:19 Uncaught TypeError: qTask.execute is not a function
at Map.js:141
at K (dojo.js:18)
at dojo.js:19
at E (dojo.js:19)
at da (dojo.js:19)
at e (dojo.js:21)
at HTMLScriptElement.<anonymous> (dojo.js:23)

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

  Sounds like your requires are not in sync with their vars then. Can I see more of your code?