Select to view content in your preferred language

How can i access answers to a specific question in a collection of repeats

124
2
Jump to solution
2 weeks ago
Trippetoe
Frequent Contributor

Hello. I'm wondering how to get the all values from a 'select_one' question that exists within a repeat. Ultimately, I'd like to use that list of values in a 'search()' expression to populate the list of values to that select_one in the 'next' repeat. I'm confused just re-reading that last sentence, so here's some background.

My survey is used to track 'treatments' of various trees. Each tree has a unique 'tree tag id'. A single survey can be used to track treatments for any number of trees. The 'TreeTagId' is a select_one question within a repeat. I am hoping to create a drop-down list of tree tag ids that does not include any tree tag ids already selected in the survey. To do that, I'm using the approach described here to create a URL query that excludes previously selected tree tags. So, something like where=treetagid NOT IN ('101', '102', '103') . In that example, the user has completed three 'repeats' and selected tree tag ids 101, 102, 103. So in the 4th repeat, none of those TreeTagIds would be in the select_one list.  I hope that makes sense....

As a new repeat is added, I am hoping to somehow 'iterate' over the previous repeats, pull out the value of the 'TreeTagId' question and append it on to the 'where' statement to be used in the 'search()' calculation for the TreeTagId select_one of the new repeat. Is such a thing possible?

Thank you

0 Kudos
1 Solution

Accepted Solutions
Neal_t_k
Frequent Contributor

I think what you are after is the join function 

https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformformulas.htm

make a helper field outside of your repeat, and the calculate all the answers from the TreeTagID  question in the repeat to generate your list for the for the where clause.  You will most likely need a helper question for the where clause as well and the URL do much better if you don't perform calcs in them

join(',', ${TreeTagId)

concat ("where=treetagid NOT IN (",${JoinList},")")

edit: I am not sure how that will work as more repeats are added, you will have to test that to see if it functions as you suspect. 

View solution in original post

2 Replies
Neal_t_k
Frequent Contributor

I think what you are after is the join function 

https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformformulas.htm

make a helper field outside of your repeat, and the calculate all the answers from the TreeTagID  question in the repeat to generate your list for the for the where clause.  You will most likely need a helper question for the where clause as well and the URL do much better if you don't perform calcs in them

join(',', ${TreeTagId)

concat ("where=treetagid NOT IN (",${JoinList},")")

edit: I am not sure how that will work as more repeats are added, you will have to test that to see if it functions as you suspect. 

Trippetoe
Frequent Contributor

Perfect! 'join' is exactly what I was looking for. Thank you. A few 'concat' statements later, i've got the sql query working exactly as needed.

0 Kudos