Method to build a string to reference another question, based on repeat number?

962
5
01-19-2022 05:48 PM
DuncanKinnear
New Contributor III

I'm trying to build a workaround to this idea: https://community.esri.com/t5/arcgis-survey123-ideas/appearance-option-to-view-repeats-stacked-in/id...- i.e. viewing a summary of repeats in tabular format. I actually want questions in my repeat to update based on how the user edits data in the summary grid, instead of having to scroll through each repeat to do this. For example, updating plant heights once all plants have been collected.

To do this I want a question within my repeat to reference some extra questions I've created, based on the repeat number. So, for repeat number 1, I want to bring in the value from '${species_height_1}' - which sits outside the repeat. If I hardcode this, it works, but if I try to build a string to reference this i.e.:

concat("${species_height_", position(..), "}"), Survey123 seems to read it literally and I get this error:

DuncanKinnear_0-1642643143219.png

 

Any ideas how to make this work? I can build a workaround to this using a long-winded if statement (ideally we want to have up to ~50 species available...), or using a javascript function, but I feel like this is a cleaner and faster solution.

Cheers

0 Kudos
5 Replies
JesseKalwij1
New Contributor III

I would do the concatenate as a calculation with a new field name and a hifden appearance, and then a second row using a Note to show the result of the new field name, all within the repeat at the species level.

0 Kudos
DuncanKinnear
New Contributor III

Thanks for the suggestion - I've tried something like that but with the same result. Also tried using a select_one with a list of possible question names but that didn't work either. Have you got a working example by chance? Cheers.

0 Kudos
DerrickWestoby
Occasional Contributor III

How about join()

DerrickWestoby_0-1643045447141.png

Inside of my repeat, I have 2x hidden fields that construction a label string to summarize all collected samples (One of which filters to features that have a group assigned). 

Outside of my repeat, I'm using the join() function to summarize all repeat records in a note. 

(outside of repeat)

note | summary_asbestos | Summary of samples collected: | concat(join("<br> ",${sampleString_asbestos}))

(Inside of repeat)

hidden | sampleString_asbestos | Returns a string to summarize all asbestos samples collected | concat(${entry_ID_asbestos},' - ',${material_code_asbestos},' - ',${description_asbestos},' - bld',${building_asbestos},' - flr',${floor_asbestos},' - rm',${room_asbestos},${populate_samplegroup_asbestos})

 

The calculation for the field that's only including records with a group entered:

if(${sample_group_asbestos},concat(${entry_ID_asbestos},' - ',${material_code_asbestos},' - ',${description_asbestos},' - bld',${building_asbestos},' - flr',${floor_asbestos},' - rm',${room_asbestos},${populate_samplegroup_asbestos}),'')

 

 

 

0 Kudos
DuncanKinnear
New Contributor III

Thanks, this is a neat way of summarising data, but I probably didn't explain well enough. I actually want the 'summary' questions outside of the repeat to be editable, and for the repeat questions to update based on those. So I need the question within the repeat to reference the relevant question outside of the repeat, i.e. repeat No. 1 references '${species_height_1}' etc. I can do this with JavaScript or a long-winded if-else statement, but would like to build the string based on repeat position if possible..

0 Kudos
EvanJohnson
New Contributor II

Hi Duncan, I totally get what you are trying to do here and am wondering if you ever solved the dynamic field reference? I'd appreciate to know if this is possible or not!

0 Kudos