Select to view content in your preferred language

Help! search() function not working as documented

945
6
03-08-2023 11:09 AM
Vince_ERAC
Regular Contributor

Hey all,

Hoping someone can help figure out why the search() function isn't working as documented. 

Overview

I have a hosted feature layer that contains a parent table with event details, and a child table which has attendees that can be recorded for that event via a repeat.

I'm trying to put together a search query that can generate a list of attendees for a specific event based on parentglobalid's. 

Looking at the documentation for the search() function, an example query was the following:

search('csvName', 'matches', 'breed', ${DogQuestion})

I put together a very similar query as follows (except I call the related table instead of a csv):

search('example_search?url=<REST url>/FeatureServer/3', 'matches', 'parentglobalid', ${parentglobalid})

The searchColumn "parentglobalid" is the name of the field in the related table, and the searchText of ${parentglobalid} refers to a question in the survey that stores the parentglobalid. 

In theory, this should work however it returns a list of all records from the attendance field instead of just the ones that match the parentglobalid:

Vinzafy_0-1678302007366.png

To check that this search query is correct, I replaced ${parentglobalid} with an actual value for a parentglobalid in the feature layer and this worked as expected - only attendees for that specific event were returned:

search('example_search?url=<REST url>/FeatureServer/3', 'matches', 'parentglobalid', '57ad118f-bcb0-41a1-8268-c2d2b7f79512')

Vinzafy_1-1678302115138.png

It seems the search() function only works when the searchText is a string enclosed in quotes (static), however the documentation shows that it can reference a field (dynamic) but that's not working in my case. 

Troubleshooting Attempts

The things I've tried are the following (none of them worked):

  • Create a separate text question that stores the parentglobalid a second time and call that in the search() function 

  • In that separate text question, ensure the parentglobalid is a string and call that in the search() function

  • In that separate text question, enclose the parentglobalid with quotation marks ( concat("'", ${parentglobalid}, "'") ) and call that in the search() function

  • Call a completely irrelevant field as the serachText value which still returns the entire list

  • Have a separate calculate question that stores the ensure search() function and have the appearance call that calculated value

  • Have a separate calculate question that stores the body of the search() function and have the appearance call the calculate within the search function (e.g., search(${search_body})

Hopefully I'm missing something straightforward and this is a quick fix. Or maybe it's not possible to run the search() function using parentglobalid's, however it just doesn't seem to want to work when calling a field dynamically. 

Any help or advice would be much appreciated!

0 Kudos
6 Replies
JJ_Reyes
Regular Contributor

@Vince_ERAC - did you ever get this working? I'm having a similar problem with a GUID.

0 Kudos
Vince_ERAC
Regular Contributor

Hey there. Unfortunately not  ☹️

Thankfully in my case, we changed the attendance workflow so generating a dynamic list based on relationship classes was no longer needed. Trying to figure out how to get the search() function working when calling a field so it can be dynamic is still on the list for me to look into further though. 

Feel free to copy any of the text or images here if you'd like to start your own post in the forums. Someone out there has to know the solution! 

0 Kudos
JJ_Reyes
Regular Contributor

Figured it out. If using a GUID, you have to use 'contains' instead of 'matches'.

Vince_ERAC
Regular Contributor

Nice! Glad you have it working for you. Did you just use a similar syntax as the following?

search('example_search?url=<REST url>/FeatureServer/3', 'contains', 'parentglobalid', '${parentglobalid}')

Unfortunately I still can't get it to work on my end. Whether contains or matches is used as the operator, when calling the parentlgobalid dynamically from a field, it still returns every record from that table as opposed to just the records that truly match the parentglobalid. 

0 Kudos
JJ_Reyes
Regular Contributor

Rats! Without the single quotes on the field worked for me:

search('example_search?url=<REST url>/FeatureServer/1','contains','field_guid',${GUID})

0 Kudos
Vince_ERAC
Regular Contributor

Awesome, glad it's solved on your end.Thanks for sharing what worked for you! I'll keep playing around with the search query and hopefully find something that works. If I find what the issue is, I'll be sure update this thread.

All the best!

0 Kudos