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
Solved! Go to Solution.
you have made a typo error it is not esriQuery.where = "SUPPORTID =='" + supportId + "'"; it should be query.where....
Chris,
your SQL sntax should not have equal equal.
esriQuery.where = "SUPPORTID = '" + supportId + "'";
I updated my code to that, but I still receive the following: {"error":{"code":400,"message":"Unable to complete operation.","details":[]}}
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;
It's an esriInteger, but does not appear to populate the where statement:
I got this from the network tab.
you have made a typo error it is not esriQuery.where = "SUPPORTID =='" + supportId + "'"; it should be query.where....
Thanks
thejus I was focusing on the SQL statement and missed that.
also you may want to use query = new esriQuery();
I updated that as well.
That did it. Thanks.