Combine references to create new reference like ${var${randnum}}

292 views Asked by At

I am trying to create a new reference containing another reference as in ${var${randnum}}. Ultimately, I want to create a variable which refers to a two times two randomized set of variables. As the above approach did not work, I developed it further with below result.

In the calculate field I write
concat('$','{','trust',${rand_no2},'_' ,${rand_no3_1},'}')

Which should result in
${trust1_1}
and respective combinations.

Without line 11 (name=ref2) the file compiles and I can start it in ODK Collect (v.2.4) on my phone. When I reach line 10 (in ODK Collect), however, I receive the message: "Error Occured Dependency cycle in s; recursion limit exceeded!!" (I included line 11 to show what I want to do in the end.)

I am writing the file in Excel and compile it with ODK xlsform offline. (For testing I transfer it via cable to my phone.)

The xls file for reproduction can be found here: https://forum.getodk.org/t/concatenate-references-to-create-new-reference-var-randnum/34968

Thank you very much in advance!

1

There are 1 answers

1
Martijn van de Rijdt On BEST ANSWER

You're mixing up some things related to the ${q} syntax, question names and question values.

Note that ODK Collect does not actually understand the ${q} syntax (which is XLSForm-only). It's helpful to look at the actual form format that ODK collect understands which is called XForm, an XML format that XLSForm converts into. However, even if ODK Collect understood the ${q} syntax, your approach still wouldn't work since you're creating a string value for the ref question (using concat). This wouldn't magically be evaluated as a reference / formula. You cannot dynamically create a reference or formula.

At the moment (until ODK supports something like the local-name() function), maybe the best approach is to use position and put the calculated values inside a group. Something like //group/calc[number(${pos})] perhaps. Note that positions are 1-based (so the first item is position 1) and casting the position to a number or integer is required.