Include Variable Name in ArcGIS Server Query Statement

581
2
Jump to solution
07-26-2019 10:14 AM
PaulMcCord
Occasional Contributor

I'm using the ArcGIS API for JS to query a Feature Layer hosted on ArcGIS Server. I'm trying to include a variable name in my "where" statement. For example:

var params = new Query({
  returnGeometry: true,
  outFields: ["*"]
});

params.where = "PropOwner = 'City' AND Location = commName";‍‍‍‍‍‍

In the above, I'm querying buildings where the Property Owner field is populated with "City" and commName is a variable defined when a user selects a location from a drop down list. However, my query doesn't work when I pass it the variable commName. 

I'm sure there is a simple way to do this. How do I need to revise my where statement to successfully pass it a variable name (in this case, commName)? 

Tags (1)
1 Solution

Accepted Solutions
PaulMcCord
Occasional Contributor

Thanks Robert, I was able to get it to work with a slight modification to your suggestion:

params.where = "PropOwner = 'City' AND Location = '" + commName + "'";

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Paul,

  Then the line would look like this:

params.where = "PropOwner = 'City' AND Location = " + commName;
PaulMcCord
Occasional Contributor

Thanks Robert, I was able to get it to work with a slight modification to your suggestion:

params.where = "PropOwner = 'City' AND Location = '" + commName + "'";