Hi everyone, I adapted this sample from ESRI staff to search a Feature Service for ONE attribute, but I have not been able to figure out how to have it search multiple fields:
JS Bin - Collaborative JavaScript Debugging
I referenced the following resource, to try to query multiple attribute fields with no success, even though AND/OR seems like a viable option for .where
Query (Feature Service/Layer)—ArcGIS REST API: Services Directory | ArcGIS for Developers
function doQuery() {
// Set the search text to the value of the input box
document.getElementById("inputTxt").value
queryParams.where = "Barcode LIKE '%" + document.getElementById("inputTxt").value + "%'";
layer.queryFeatures(queryParams).then(showResults);
}
Any suggestions to search multiple feature service fields for one keyword?
I'm fresh to JavaScript.
Thanks!
Solved! Go to Solution.
Hi Jeff,
An OR operator should work. I usually navigate to the rest service URL and execute the query there to be sure it's working successfully. Below is an example that I believe should work:
val = document.getElementById("inputTxt").value
queryParams.where = "Barcode LIKE '%" + val + "%' OR NewField LIKE '%" + val + "%'";
Hi Jeff,
An OR operator should work. I usually navigate to the rest service URL and execute the query there to be sure it's working successfully. Below is an example that I believe should work:
val = document.getElementById("inputTxt").value
queryParams.where = "Barcode LIKE '%" + val + "%' OR NewField LIKE '%" + val + "%'";
I like how you turned the user input into a variable. Thanks for the help with the structure of the query! This works!
Yeah, I originally did not and felt like my head was going to explode trying to keep track of all the quotations