var gp, map, toc, dynaLayer1, query, queryTask;    var geocoder;       var symbol, infoTemplate, extractMethod;       var AOI, graphic, clipFeatureSet, clipFeature;       require(["dojo/_base/connect",          "dojo/dom", "dojo/dom-style", "dojo/parser", "dojo/on", "dojo/_base/Color",          "esri/map", "esri/config",          "esri/dijit/HomeButton",          "esri/dijit/BasemapGallery",          "esri/dijit/Bookmarks",          "esri/dijit/Scalebar",          "esri/geometry/Extent",          "esri/tasks/query", "esri/tasks/QueryTask",          "esri/layers/FeatureLayer",          "esri/layers/ArcGISTiledMapServiceLayer",          "esri/layers/ArcGISDynamicMapServiceLayer",          "esri/symbols/SimpleFillSymbol",          "esri/symbols/SimpleLineSymbol",          "esri/InfoTemplate",    "esri/tasks/FeatureSet",    "esri/graphic",          "agsjs/dijit/TOC",          "dijit/registry",          "dijit/layout/BorderContainer",          "dijit/layout/ContentPane",          "dijit/layout/AccordionContainer",          "dijit/TitlePane",          "dijit/form/CheckBox",          "dijit/form/ComboBox",          "dojo/parser",          "dijit/Toolbar",          "dijit/form/DropDownButton",    "dijit/layout/TabContainer",          "dijit/form/TextBox",          "dijit/TooltipDialog",          "dijit/ToolbarSeparator",          "dojo/domReady!"       ], function (connect, dom, domStyle, parser, on, Color,          Map, esriConfig, HomeButton, BasemapGallery, Bookmarks, Scalebar, Extent, Query, QueryTask, FeatureLayer, ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer,          SimpleFillSymbol, SimpleLineSymbol, InfoTemplate, FeatureSet, Graphic,          TOC, registry) {           // call the parser to create the dijit layout dijits          parser.parse(); // note djConfig.parseOnLoad = false;           // Specify where the location of the proxy to use to communicate with the extract GP service.          esriConfig.defaults.io.proxyUrl = "/proxy";            // Keep a reference to the loading icon DOM node.          var loading = dom.byId("loading");                     map = new Map("map", {             logo: true,             sliderPosition: "top-right",             basemap: "topo",             center: [-121.469, 38.556],             zoom: 8          });           var home = new HomeButton({             map: map          }, "HomeButton");          home.startup();           var basemapGallery = new BasemapGallery({             showArcGISBasemaps: true,             map: map          }, "basemapGallery");          basemapGallery.startup();                  var bookmarks = new Bookmarks({             map: map,             bookmarks: [],             editable: true          }, dom.byId('bookmarks'));           var scalebar = new Scalebar({             map: map,             // "dual" displays both miles and kilmometers             // "english" is the default, which displays miles             // use "metric" for kilometers             scalebarUnit: "dual",             scalebarStyle: "ruler",             attachTo: "bottom-left"          });           dynaLayer1 = new ArcGISDynamicMapServiceLayer("http://webgisdevint1/arcgis/rest/services/Alex_Try/Archived/MapServer", {});           map.on('layers-add-result', function (evt) {             dynaLayer1.setVisibleLayers([1, 2, 4]);             toc = new TOC({                map: map,                layerInfos: [{                   layer: dynaLayer1,                   title: "Layers",                   slider: true                }]             }, 'tocdiv');             toc.startup();          });          map.addLayers([dynaLayer1]);            symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,             new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([111, 0, 255]), 2), new Color([255, 255, 0, 0.25]));          infoTemplate = new InfoTemplate("${OBJECTID}", "${*}");           registry.byId("query").on("click", executeQuery);           function executeQuery(name) {                 var name = document.getElementById("user").value       var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/Archived/MapServer/0");             queryTask.on("complete", showResults)    var query = new Query();             query.returnGeometry = true;             query.outFields = ["LAST_EDITED_USER"];             query.where = "LAST_EDITED_USER = '" + name + "'";             query.outSpatialReference = map.spatialReference;             queryTask.execute(query, showResults);    }           function showResults(featureSet) {          //remove all graphics on the maps graphics layer          map.graphics.clear();           //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;          graphic.setSymbol(symbol);           //Set the infoTemplate.          graphic.setInfoTemplate(infoTemplate);           //Add graphic to the map graphics layer.          map.graphics.add(graphic);         }        }"Cannot read property 'length' of undefined"
Solved! Go to Solution.
queryTask.execute(query, showResults(featureSet) { alert(featureSet.length);});
queryTask.execute(query, function(featureSet) { alert(featureSet.length);});
Your codes may have multiple problems, but first off, ...
Change fromqueryTask.execute(query, showResults(featureSet) { alert(featureSet.length);});
ToqueryTask.execute(query, function(featureSet) { alert(featureSet.length);});
Then, you can start from there.
1. Did you see any popup with a number?
2. To limit other errors, you can comment all codes afterward.
function showResults(results) {
var features = results.featureSet.features
....
You shouldn't combine a queryTask.on('complete', showResults) with a queryTask.execute(query, function ....). You have already specified your results handler, putting something different in the execute line just confuses things.
Also, if you execute with a listener on the 'complete' event, I believe the resultant output is generically 'results' and not a featureSet. You end up having to change your code up slightly to get to the featureSet, something likefunction showResults(results) { var features = results.featureSet.features ....
Pay attention to what is really getting returned from your query handler, I don't think it's a featureSet.
"results i not defined"
function showResults(featureSet){ var features = featureSet.features; queryTask.execute(query, handlerFunction);
function showResults (results) { var features = results. featureSet.features;for (var i=0; i<features.length; i++){If you're going to remove the queryTask.on ('complete', handlerFunction), and stick with queryTask.execute(query, handlerFunction) then you want to leave your showResults function asfunction showResults(featureSet){ var features = featureSet.features;
If you want to want to go withqueryTask.execute(query, handlerFunction);
That's where you'd have your results function asfunction showResults (results) { var features = results. featureSet.features;
I also think your for statement looks a little weird. Maybe it should befor (var i=0; i<features.length; i++){
