AnsweredAssumed Answered

Query and QueryTask

Question asked by margaraiz on Sep 19, 2016
Latest reply on Sep 22, 2016 by rscheitlin



I have been trying to query a layer and show the results in the map but I can't make it work, this is my try:


define([ 'jimu/BaseWidget', 'dojo/_base/connect', 'dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', 'dojo/_base/html', 'dojo/dom', 'dojo/on', 'dojo/query', 'esri/tasks/QueryTask', 'dijit/registry', 'esri/layers/FeatureLayer', 'esri/layers/Field','esri/request', 'dojo/store/Memory','jimu/LayerInfos/LayerInfos' ],

function (BaseWidget, connect, declare, lang, array, html, dom, on, Query, QueryTask, registry, FeatureLayer, field, esriRequest, Memory, LayerInfos) { return declare([BaseWidget], {
          baseClass: 'jimu-widget-mywidget',
          startup: function () {
              var map =;
              queryTask = new QueryTask("");
              query = new Query();
              query.returnGeometry = true;
              query.outFields = ["OBJECTID"];


              if (map.loaded) {
                  query.where = "OBJECTID = 1";
                  queryTask.execute(query, showResults);
              } else {
                  map.on("load", function () {
                      query.where = "OBJECTID = 1";
                      queryTask.execute(query, showResults);
                function showResults(featureSet) {

                    //Performance enhancer - assign featureSet array to a single variable.
                    var resultFeatures = featureSet.features;

                    //Loop through each feature returned
                    for (var i=0, il=resultFeatures.length; i<il; i++) {
                    //Get the current feature from the featureSet.
                    //Feature is a graphic
                    var graphic = resultFeatures[i];

                    //Set the infoTemplate.

                    //Add graphic to the map graphics layer.





I get this mistake:


TypeError: a.toJson is not a function 





Can any one tell me if I am using query and querytask in the correct way? I have been following other threats of this forum to write this piece of code.