I am using query task to do a attribute query for features with a where clause. I have verified that the specific layer I am querying has the field LK_ID_NUM.

My query task do not return an error, but no features are found. Therefore the results.features returns undefined. I checked the where condition (LK_ID_NUM = 46014) directly on the ArcGIS Rest service and the query returns a feature successfully. I tried the query without the where clause, and it still did not return any features, only the feature layer information is returned.

I Thought the issue is that i require a geometry input to the query. I tried added a extent geometry and changed the spatial relationship to "Contains". But this did not solve the issue. There is still no features returned.

My JS query code is shown below.

                    task.featureLayer = layer;
                    task.queryTask = new QueryTask( this.validateUrlToken.addTokenIfApplicable( layerUrl ) );
                    task.query = new Query();
                    task.query.outFields = [
                    task.query.returnGeometry = true;
                    task.query.outSpatialReference = this.map.map.spatialReference;         
                    var whereclause = "LK_ID_NUM = " + gislink  ;
                    task.query.where = whereclause;    //only query features that has same LinkID
                    console.log("query condition: ", whereclause);
                    tasks.push( task );
                    console.log("Query Tasks captured: ",task);

                    var defferedTask = task.queryTask.execute( task.query );
                    this.aDeferreds.push( defferedTask );

                    promises = all( this.aDeferreds );
                    promises.then( lang.hitch( this, this.handlelinkResults ), lang.hitch( this, function ( err ) {
                    console.error( 'query error', err );
                    this.stopTimeout = true;
                    if ( this.errorType == null ) {
                        var errorMessage;
                        if ( err.message ) {
                            errorMessage = err.message;
                        } else {
                            errorMessage = err;

                } ) );

handlelinkResults: function(r) {
        //console.log("Check if handle link results function is used");
        var features = [];
        var featuresValue = [];
        var featuresLayersIds = [];
        var featuresCountForFeaturesLayers = 0;
        var featuresCountForDynamicLayers = 0;

        //console.log("Debug what is r:", r);
            console.log("debug results:", result);
            var resultfeat = result.features;
            if ( resultfeat && resultfeat.length > 0) {
                array.forEach( resultfeat, function ( feat, j ) {
                    var value = feat.value + "_" + feat.layerId;
                    var layerNameId = this.featureLayersNameId[ this.layersRequest[ j ] ];
                    feat.attributes.layerName = layerNameId.layerName;
                    feat.attributes.layerId = layerNameId.layerId;
                    feat.urlLayer = this.layersQueryTask[featuresCountForDynamicLayers].url + "/" + layerId;
                    feat.layerInfos = this.layersQueryTask[featuresCountForDynamicLayers].layerInfos;
                    feat.layer = this.layersQueryTask[featuresCountForDynamicLayers];
                    feat.layer = this.layersQueryTask[featuresCountForDynamicLayers];
                    features.push( feat );
                }, this );}

I included the screenshots below. The first image is the query that I constructed and logged in console for debugging. The second image is the returned results. I do not see any feature element in the result for my query.

Where did I go wrong?

enter image description here

enter image description here

  • You placed quotes around the numeric in the WHERE clause. If the field is integer, this is incorrect.
    – Vince
    May 12, 2021 at 11:02
  • Hi, Thank you so much for your reply. I tried changing it to "LK_ID_NUM = 46014" but the issue still persists. You are right the field is LK_ID_NUM ( type: esriFieldTypeInteger , alias: LK_ID_NUM ).
    – LZa
    May 12, 2021 at 11:36
  • I think you need to show your JS code. Your response screen shot doesn't look like the output of a featureservice query. It looks like the definition of the service.
    – KHibma
    May 12, 2021 at 11:43
  • I have updated the post to include my JS code. Appreciate it. Thank you
    – LZa
    May 12, 2021 at 11:50

1 Answer 1


I found the issue. It has to do with the layer URL input. The initial url variable was stored as something like this (https://xxx/arcgis/rest/services/xxx/xxxx/MapServer/). This is ok for identify tasks but for query tasks it requires the layer ID (something like this https://xxx/arcgis/rest/services/xxx/xxxx/MapServer/0). All i had to do was to include the layer ID and the query returned the feature as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.