I'm trying to use query tasks to extract attributes of a feature based on what was selected from a filtering select list(setVal = "Chain Lakes Provincial Recreation Area"). But I get the error

TypeError: Cannot read property 'length' of undefined(…)

from the line of code

for (var i = 0, il = resultFeatures.length; i < il; i++) {

in the following:

        queryTask = new       QueryTask("http://www.arcgis.com/sharing/rest/content/items/1d890f37f9f049d1b499141511235b5b/data");
        //initialize query
        query = new Query();
        query.returnGeometry = true;
        query.outFields = ["OC_NAME", "TYPE", "ACRES"];

        //create symbol for selected features
        symbol = new SimpleMarkerSymbol();
        symbol.setColor(new Color([255, 255, 0, 0.5]));

        function showResults(featureSet) {
            //remove all graphics on the maps graphics layer

            //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.

        function executeQueryTask() {
            //set query based on what user typed in for population;
            query.where = "OC_NAME = '" + selVal + "'";
            //execute query
            queryTask.execute(query, showResults);
  • 1
    the error is telling you that the actual query didnt return any results. you should snoop the network traffic to inspect the actual request parameters and response to try and determine why. – John Gravois Oct 14 '16 at 20:40

you used url is not supported query task. check this url and look for source.


i have a suggestion but this suggestion run client side

                url: "http://www.arcgis.com/sharing/rest/content/items/1d890f37f9f049d1b499141511235b5b/data",

            }).then(function (response) {
                        features = response.layers[0].featureSet.features;
                        featureLayer = new FeatureLayer(response.layers[0], {
                            //infoTemplate: ...
                        showResults(executeQueryTask("OC_NAME", 'Chain Lakes Provincial Recreation Area'));

            function executeQueryTask(attribute, value) {
                return features.filter(function (feature) {
                    return feature.attributes[attribute] == value;

            function showResults(features) {
                var extent = null
                features.forEach(function (graphic) {
                    extent = extent ? extent.union(graphic.geometry.getExtent()) : graphic.geometry.getExtent();
                if(extent) map.setExtent(extent.expand(2));

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.