Search query syntax for searching two fields

864
6
Jump to solution
04-10-2018 07:30 AM
MeganWirth
Occasional Contributor

Trying to perform a query task that searches two separate fields. The user text input can either be the Name field or a Docket field.

// Executes on each button click
function doQuery() {
// Set the search text to the value of the input box
document.getElementById("inputTxt").value
queryParams.where = "Name like '%" + document.getElementById("inputTxt").value + "%'";
layer.queryFeatures(queryParams).then(showResults);
}

Appreciate the help.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   If you are searching the two fields for the same value from the user input then use code like this:

var userInput = document.getElementById("inputTxt").value;
queryParams.where = "Name like '%" + userInput + "%' OR Docket like '%" + userInput + "%'";

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   If you are searching the two fields for the same value from the user input then use code like this:

var userInput = document.getElementById("inputTxt").value;
queryParams.where = "Name like '%" + userInput + "%' OR Docket like '%" + userInput + "%'";
MeganWirth
Occasional Contributor

Sorry Robert, I should be more clear. The user will either search by one field or another. So it would be different values.

Example. The user could know the subdivision name or the docket number. Would like them to be able to search by either option.

Name = RNJ or Docket = 1-15-2018

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

So do you have two different user inputs? How do you determine which they are searching for?

0 Kudos
MeganWirth
Occasional Contributor

Only one user text input. Im using this example http://jsbin.com/veyaqa/edit?html,output

As always. Thanks for your time Robert!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

  Then you will have to add a checkbox, dropdown or something that will distinguish which field they want to search one or you just use the code I posted in my first reply and let it search both fields for the entered value.

0 Kudos
MeganWirth
Occasional Contributor

Im an idiot lol. It works perfectly. Thank you Sir!

0 Kudos