Why Won't My Query Count the Related Features?

2889
9
Jump to solution
06-10-2015 09:25 AM
ChrisSergent
Regular Contributor III

I am trying to count the related features when the user clicks on a feature, but my query won't run. An example of what I am trying to do in our REST Service directory is the following:

The Where Statement: SUPPORTID='691'

The URL to run the where statement: Layer: Sign (ID: 0)

I have also published app at: maps.decaturil.gov/streetSigns/

And the latest version is on github at: csergent45/streetSigns at 297fa633f0ebb529862e35b7019c04d7259fbfe8 · GitHub

In my code, I have entered the following for the code block to run the query and to display a count in the console, but it's not working:

// url the query task is to be performed on
            var queryTask = new QueryTask(config.signLayerUrl);
            var query = esriQuery();


            // count related records
            esriQuery.where = "SUPPORTID =='" + supportId + "'";
            // display number of related records in console
            queryTask.executeForCount(query,function(count){
                console.log(count);
            })

The supportId is the support ID of the feature that was clicked on.

The config.signLayerUrl is the URL that I am querying.

Why doesn't this work? I referenced the API at: https://developers.arcgis.com/javascript/jsapi/querytask-amd.html#executeforcount

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

you have made a typo error it is not esriQuery.where = "SUPPORTID =='" + supportId + "'";  it should be query.where....

View solution in original post

9 Replies
RobertScheitlin__GISP
MVP Emeritus

Chris,

   your SQL sntax should not have equal equal.

esriQuery.where = "SUPPORTID = '" + supportId + "'";

ChrisSergent
Regular Contributor III

I updated my code to that, but I still receive the following: {"error":{"code":400,"message":"Unable to complete operation.","details":[]}}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

What type of field is SUPPORTID? If it is a numeric field then your SQL Syntax should look like this instead:

esriQuery.where = "SUPPORTID = " + supportId;

ChrisSergent
Regular Contributor III

It's an esriInteger, but does not appear to populate the where statement:

  1. f:json
  2. returnIdsOnly:true
  3. returnCountOnly:true
  4. where:
  5. returnGeometry:false
  6. spatialRel:esriSpatialRelIntersects

I got this from the network tab.

0 Kudos
thejuskambi
Occasional Contributor III

you have made a typo error it is not esriQuery.where = "SUPPORTID =='" + supportId + "'";  it should be query.where....

RobertScheitlin__GISP
MVP Emeritus

Thanks

thejus I was focusing on the SQL statement and missed that.

thejuskambi
Occasional Contributor III

also you may want to use query = new esriQuery();

ChrisSergent
Regular Contributor III

I updated that as well.

0 Kudos
ChrisSergent
Regular Contributor III

That did it. Thanks.

0 Kudos