Referencing dataset - label from select_one as text in next question

1. What is the issue? Please be detailed.
In my form I have an external csv select_one_from_file question and a subsequent text question. I am using the appearance map and it works great!

I would like to set the default for the text question to be the label for the select_one (this is essentially an opportunity to update the existing description if necessary)

The select_one_from_file works (so I know it is correctly set up)
The next question remains blank.

In the example within the sample xlsx I'm using the select_one question is called Surfacing1
In the column for default of the next question I am using: instance("surface")/root/item[name = ${Surfacing1}]/label

which in my naive understanding of XPath should evaluate to the label of the item corresponding to the value Surfacing1 from the list_name surface...

I am also trying to reference other columns in the csv, but they don't work, so let's just start with the label...

I've also tried it with an internal list as select_one (appearance minimal) and get the same result - blank next question.

2. What steps can we take to reproduce this issue?

I produced a skeleton form but it doesn't parse, so I'm a bit stuck. And yet the big form (which I'm not sharing) validates fine. Which is a bit odd. I tried adding choice_filter True() to the skeleton just in case but no joy

Response from Central and XLSForm online
Error: ODK Validate Errors:

Something broke the parser. See above for a hint.
org.javarosa.xpath.XPathMissingInstanceException: XPath evaluation: Instance referenced by instance(surface)/root/item/label does not exist

The following files failed validation:
${select-one-label}.xml

Result: Invalid

Maybe if I can get to the bottom of this, it might help? No idea why one would work and the other not!

3. What have you tried to fix the issue?
followed the documentation: https://docs.getodk.org/form-datasets/#referencing-values-in-datasets
This even has the example of picking up the label from an external dataset, so I used this as the model...

I have been able to use the following question to show the value in a label, but not set the default value of the question: Referring to a label of an answer to previous choose one question, within the label of subsequent question

This doesn't really solve my problem and adds extra columns to my dataset, so I don't see it as a viable answer...

4. Upload any test forms or screenshots below.
I'm using ODK Central 1.5.3 and ODK Collect v2022.3.6
select-one-label.xlsx (12.0 KB)

Any help gratefully received. No doubt it will be the usual problem of a minor error that I can't see for looking at.

Hi there @seewhy!
A couple of resources that might be helpful to you - sorry, just have taken a quick look at this, but let us know if this doesn't exactly match what you need:

ODK Docs - check out https://docs.getodk.org/form-logic/#dynamic-defaults-from-form-data for using the 'calculation' column & 'trigger' column for getting default data from form responses (as the 'default' column only calculates at form creation)

Also - if you look about halfway through this video on select_one_from_file - shows the xpath being used in a 'calculation' question - if it's helpful. https://youtu.be/yiRsH1vvcBU

Hope this helps?
Janna

1 Like

Thanks @janna

I knew it would be a simple error. The connection between default value and triggering an update wasn't on my radar! I think I've actually done that before but it didn't trigger any neurons this time around. At least this is on the forum now - I like the way that the Docs cross reference things, so a link between the reference I used and the one you provided would be a good one to help other fools like me :slight_smile:

And to clarify, what I did was to move the expression

instance("surface")/root/item[name = ${Surfacing1}]/label to a column called Calculation

and

add a column called trigger and inserted the value ${Surfacing1}

And it works - so now I can pre-fill other questions based on the selection on a map and other columns on my external CSV file. Happy days!!!

As always fast and fabulous support from the ODK community.

2 Likes

woot woot! I have totally been in exactly your situation with this very 'dynamic default' question before...lol... :woman_facepalming:

1 Like

Can I make a suggestion for the Docs:

In the section https://docs.getodk.org/form-datasets/#referencing-values-in-datasets I would recommend adding something like the following after the last paragraph (maybe as a 'tip')

If you want to pre-fill data in your form on the basis of a selected value you need to use dynamic defaults so that other fields are updated when the "parent" item is changed. You can use this with internal choices, external CSV or GeoJSON files. Please see https://docs.getodk.org/form-logic/#dynamic-defaults for details

Other wording is available :slight_smile: