0

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.map.hideLoadingImg();
                    this.stopTimeout = true;
                    if ( this.errorType == null ) {
                        var errorMessage;
                        if ( err.message ) {
                            errorMessage = err.message;
                            console.log(errorMessage);
                        } else {
                            errorMessage = err;
                            console.log(errorMessage);
                        }
                    }

                } ) );

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);
        array.forEach(r,function(result,j){
            console.log("debug results:", result);
            console.log(result.features);
            var resultfeat = result.features;
            if ( resultfeat && resultfeat.length > 0) {
                array.forEach( resultfeat, function ( feat, j ) {
                    console.log(feat);
                    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 );}
        },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

4
  • You placed quotes around the numeric in the WHERE clause. If the field is integer, this is incorrect.
    – Vince
    May 12 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 ).
    – Zalim
    May 12 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 at 11:43
  • I have updated the post to include my JS code. Appreciate it. Thank you
    – Zalim
    May 12 at 11:50
0

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, privacy policy and cookie policy

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