QueryTask unable to complete operation

2687
2
04-03-2014 02:32 AM
ChristianDebono
New Contributor II
Basically I'm querying a feature layer to get the number of points in a specific polygon. I have the code working.

feature.on("click", function (evt) {
                    map.graphics.clear();
                    var highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);
                    map.graphics.add(highlightGraphic);

                    var query = new Query();
                    var queryTask = new QueryTask("featurelayer");
                    query.geometry = evt.graphic.geometry;
                    query.returnGeometry = true;
                    query.outSpatialReference = map.spatialReference;
                    query.outFields = ["*"];                    

                    queryTask.execute(query, function (results) {                        
                        alert(results.features.length);

                    });
                });


My problem is that in some specific polygons the count is not being worked out and I'm getting "unable to complete operation" error in the console of Chrome browser

_ssl: undefined
code: 400
details: Array[1]
httpCode: 400
log: undefined
message: "Unable to complete operation."
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: d


Any ideas why this is happening. I could not understand how in major of the polygons drawn the queryTask is working and in some I'm getting this error. Thanks for your help
0 Kudos
2 Replies
TracySchloss
Frequent Contributor
A couple of things come to mind:  It could be that some of your polygons have more vertices and you need to have a proxy page set up to handle the number of features.  There's lots of threads that discuss when and why you need a proxy configured. 

Another thing could be that the sometimes when you've made a request that's going to return a lot of information, the result function is trying to run before the  task is completely done executing.  You can try changing your code so that it doesn't fire the results function until the query is completed.

feature.on("click", function (evt) {
                    map.graphics.clear();
                    var highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);
                    map.graphics.add(highlightGraphic);

                    var query = new Query();
                    var queryTask = new QueryTask("featurelayer");
                    query.geometry = evt.graphic.geometry;
                    query.returnGeometry = true;
                    query.outSpatialReference = map.spatialReference;
                    query.outFields = ["*"];                    
                    queryTask.on('complete', queryResultsHandler);
                    queryTask.execute(query);

                    });
                });
function queryResultsHandler(results){
alert(results.features.length);
}
0 Kudos
ChristianDebono
New Contributor II
Thanks for your reply Tracy. I have a proxy page set to my application and I have tested it and its working fine. I've also tried your code but again with no luck. I'm curious about the fact that this is only happening in some polygons; and I have some polygons which contain more features and the result is being given without any errors.
0 Kudos