Select to view content in your preferred language

Survey123: Cascading Dropdown with Conditional Visibility from External Feature Layer

164
4
4 weeks ago
FarzanehAhmadikordasiyabi
Emerging Contributor

I'm trying to create a two-part cascading dropdown in a Survey123 Connect XLSForm where the second list is filtered based on the selection from the first. Despite troubleshooting for a while, the filter isn't working, and the second list remains empty. I'd appreciate any guidance on what I might be missing.

What I'm Trying to Do

My goal is to first have a user select a department and then have a second question display only the sections related to that department.

My Data Source

I'm using a hosted feature layer in ArcGIS Portal named "Department and section" with two related tables:

  • department table (Layer 0): Contains a list of departments. Key fields are Department_id (Double) and department_branch (Text).

  • section table (Layer 1): Contains a list of sections. Key fields are department_id (Double) and section_name (Text).

The Department_id in the department table and the department_id in the section table are correctly related (e.g., department with Department_id 16 has sections with department_id 16). 

My XLSForm Configuration

Here is how my survey worksheet is configured:

Department Selection Question:

  • type: select_one departments

  • name: manual_department_name

  • appearance: search('Department and section?url=...')

Section Selection Question:

  • type: select_one sections

  • name: manual_section_name

  • appearance: search('Department and section?url=...')

The Problem

How can I 

  • filter the sections by the department selection.

  • Conditionally show the section question only if the selected department has at least one section. (There is a filed has_section in the layers with the type of text and the values of true or false)

 

0 Kudos
4 Replies
DavidSolari
MVP Regular Contributor

You can plug answers into a "where" parameter as detailed in the docs. For the first question, if your label is the department branch and your name is the id, it'll show all the names to the user but it'll pull the ID so you can feed that into the second question. If you get errors when there's no department selected, try adding a hidden question the replaces a blank department with a valid but obviously incorrect value (e.g. coalesce(${manual_department_name},-1)) and then plug that into your second question.

As for the second part, you can dig into the @pulldata functions to run a second query that returns just a count, then use that for your "relevant" check.

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

Thanks @DavidSolari for your response. The names are actually the names of of the departments. When I wanted to perform the relate on the two table I added a field department id to perform the operation. How can I set the appearance expression that shows the names of the departments to the clients but get the departments' id instead of the names? 

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

This is the screenshot of my XLS form. I get the department id of the selected department to use for query the sections, but it is not working. The data type of department_id in the layer is double. When I add the &where=department_id=${department_id} to the search() the section will show empty . What should I do?

FarzanehAhmadikordasiyabi_2-1754677758511.png

 

 

 

 

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

Hello  @IsmaelChivite Do you have any suggestions?

0 Kudos