AnsweredAssumed Answered

Valid syntax for "IN" where clause for Query, using a list of county names

Question asked by schlot on Sep 5, 2014
Latest reply on Sep 5, 2014 by schlot

Looking at my rest endpoint, I can enter a where clause of COUNTYNAME IN ('Dent', 'Holt').  I'd like to let the user enter a list of county names in an input field and parse that information into a where clause for a Query.  I assume if I can run a query from the endpoint, I ought to be able to do the same thing programmatically as long as I can get my syntax correct on my where clause.

 

The user has an input text field and they should enter county names separated by commas.    Once they click a button, a where clause is created with all the counties specified. The queryTask doesn't execute because my query syntax is wrong.

 

function checkCountyInput() {
  var countyCheck = registry.byId('countySel').get("value");
 console.log("countyCheck = " + countyCheck);
  var countyArray = countyCheck.split(",");
  console.log("countyArray = " + countyArray);
  idList.length = 0;
  countyList.length = 0;
//the syntax that worked on the REST endpoint
  //COUNTYNAME IN ('Dent', 'Holt') 
  var whereClause = "COUNTYNAME IN (" + countyArray + ")";

  query.outSpatialReference = spatialReference;
  query.returnGeometry = false;
  query.outFields = "*";

console.log("where clause = " + whereClause);
var queryTask = new QueryTask(featureLayer.url);
queryTask.on ("error", function (err) {
  console.log("error in queryTask: " + err.message);
});
queryTask.execute(query, queryCountyResults);
}

I'm I not going about this the right way?

Outcomes