Select to view content in your preferred language

Trying to get the Search() function to work with a feature service

553
3
Jump to solution
04-09-2025 01:36 PM
MaxMolello
Occasional Contributor

I'm out of ideas with the Search() function after trying all kinds of iterations. I'm simply trying to use Search() from a feature service to populate the drop down with choices from a field. The second question will do the same using the first answer as a filter

What I have for question 1 is below. I'm looking to use that feature service and populate the dropdown with all values in the field "Trail_System"

autocomplete search('trailsystem?url=https://services3.arcgis.com/AIhXi099WVQHFHhq/ArcGIS/rest/services/Trails_Public_View/FeatureServer/...')

And this doesn't return any results. I've also tried:

autocomplete search('trailname?url=https://services3.arcgis.com/AIhXi099WVQHFHhq/ArcGIS/rest/services/Trails_Public_View/FeatureServer/...', 'Trail_System'

and others with no luck. What am I missing?

0 Kudos
1 Solution

Accepted Solutions
TylerGraham2
Frequent Contributor

The problem is your choices aren't pointing to a field in the feature service to populate the choice list.  Your URL is correct, but it can't find anything because there are no fields named trail_system_search or trail_names.  In the choices tab of the xlsform change the name and label columns (leave the list_name column alone) of both lists to Trail_Name to match the Trail_Name field in the feature service and then it works.  

View solution in original post

3 Replies
TylerGraham2
Frequent Contributor

The problem is your choices aren't pointing to a field in the feature service to populate the choice list.  Your URL is correct, but it can't find anything because there are no fields named trail_system_search or trail_names.  In the choices tab of the xlsform change the name and label columns (leave the list_name column alone) of both lists to Trail_Name to match the Trail_Name field in the feature service and then it works.  

MaxMolello
Occasional Contributor

That did it, I knew something didn't seem right. Do you know if there is a way to filter out null values in that field the search uses? I got a filter to work for a test value but can't find a way to exclude nulls from the list search creates in the drop-down question.

0 Kudos
TylerGraham2
Frequent Contributor

I tried using the not() formula in the searchText and it gave me some strange results when trying to see if not('null'), or some variation thereof, would work.  You might try naming the unnamed trails to something like "unnamed" and testing if the following would work.

autocomplete search('trailname?url=https://services3.arcgis.com/AIhXi099WVQHFHhq/ArcGIS/rest/services/Trails_Public_View/FeatureServer/...', 'contains', 'Trail_Name', not('unnamed')) 

Otherwise, the way I'd go about it is to add a new field like "named_trail" and have it be yes or no. Then set up the search() appearance with a filter on it, which would look like

autocomplete search('trailname?url=https://services3.arcgis.com/AIhXi099WVQHFHhq/ArcGIS/rest/services/Trails_Public_View/FeatureServer/...', '', '', '', 'named_trail', 'yes')

It is searching for all the Trail_Name values and then filtering the results where the named_trail field is yes which should get rid of the blanks on the select_multiple.  

0 Kudos