Query Feature Service - Multiple Attribute Fields using one keyword

1174
3
Jump to solution
04-26-2018 03:17 PM
JeffWilcox1
New Contributor III

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!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

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 + "%'";

View solution in original post

3 Replies
JakeSkinner
Esri Esteemed Contributor

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 + "%'";
JeffWilcox1
New Contributor III

I like how you turned the user input into a variable. Thanks for the help with the structure of the query! This works!

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Yeah, I originally did not and felt like my head was going to explode trying to keep track of all the quotations

0 Kudos