I am using QueryTask to query an ArcGIS REST service feature class. The field I need to query is a esriFieldTypeInteger, and I am having trouble getting syntax correct in the where clause. I need to query features using a list or array of IDs and I haven't been able to find enough documentation to get the proper syntax. I am taking a string of IDs from a document input element and trying to use that list to query the features. I assume that I need to convert them to integers since the field values are integers, but am I wrong? Here is what I have tried, but the query is not executing so the problem must be with the where clause.
_getAndDisplayResults: function() {
let ifrm = window.frameElement;
console.log("iframe element ", ifrm);
let document = ifrm.ownerDocument;
console.log("document ", document);
let ids = document.getElementById("phga_ids_results").value;
console.log("phga results from text box",ids);
let numids = ids.split(',').map(Number);
console.log("phga converted results ",numids); //this returns an array of integers
let url = "https://ocean.floridamarine.org/arcgis/rest/services/.../MapServer/0";
let queryTask = new QueryTask(url);
let wmaQuery = new Query();
wmaQuery.where = "PHGA_ID IN " + numids;
console.log("where clause ", wmaQuery.where);
wmaQuery.outFields = ["*"];
wmaQuery.returnGeometry = true;
queryTask.execute(wmaQuery).then(function(result) {
console.log("wma results ", result); //get nothing here. Not executing
//let wmaArray = [];
//let features = result.features;
//features.forEach(function(feature) {
//var geometry = feature.geometry;
//wmaArray.push(feature);
//});
});
},
Any ideas as to what I have wrong with the syntax?
Thanks
Solved! Go to Solution.
Got it to work. Just missing the "()". Here is the working whereclause:
wmaQuery.where = "PHGA_ID in (" + numids + ")";
Got it to work. Just missing the "()". Here is the working whereclause:
wmaQuery.where = "PHGA_ID in (" + numids + ")";