Referencing entered data into next questions

Hi,

Can we reference some data entered as answer, into next questions? Example:
Q1 asks for name. When one enters it (Mike), the next question says his name
as part of question (Dear Mike, what is your address?). Is it possible in
ODK, and how?

Regards,

Saad

Yes, it is possible to reference a variable from a previous question using
the syntax: ${variable}. See sample xlsform attached.

name_test.xls (27.5 KB)

··· -- Need ODK forms development or training? www.geoengsystems.com

On Saturday, February 18, 2017 at 4:02:53 PM UTC+3, Saad wrote:

Hi,

Can we reference some data entered as answer, into next questions?
Example: Q1 asks for name. When one enters it (Mike), the next question
says his name as part of question (Dear Mike, what is your address?). Is it
possible in ODK, and how?

Regards,

Saad

Thanks, it worked very well. However, I am trying the next step in this
logic, and it is not working. I am trying to put the answers of first 2
questions as the options for SELECT_ONE question. The labels are working
fine, but the values submitted to aggregate at the backend are not getting
decoded into the correct variable names. Please see the attached file, and
the snapshot of data submitted on aggregate. I am also encountering
following validation alert, although my logic seems OK.

"ODK Validate Warnings:
Selection choice label text and image uri are both missing for: /dyn/game
choice: 1. Selection choice label text and image uri are both missing for:
/dyn/game choice: 2."

Any suggestions?

dyn.xls (27.5 KB)

image

··· On Sunday, 19 February 2017 07:39:02 UTC+5, Geoeng Systems wrote: > > Yes, it is possible to reference a variable from a previous question using > the syntax: ${variable}. See sample xlsform attached. > > -- > Need ODK forms development or training? > www.geoengsystems.com > > On Saturday, February 18, 2017 at 4:02:53 PM UTC+3, Saad wrote: >> >> Hi, >> >> >> >> Can we reference some data entered as answer, into next questions? >> Example: Q1 asks for name. When one enters it (Mike), the next question >> says his name as part of question (Dear Mike, what is your address?). Is it >> possible in ODK, and how? >> >> >> >> Regards, >> >> Saad >> >

This may not be possible in the current toolset. It probably has something
to do with when the model in xml is validated, and therefore you cant use
variables as choice names.

Mitch or Yaw can elaborate further on why this is not possible, and if
there is any plan to make it possible.

··· -- Need ODK forms development or training? www.geoengsystems.com

On Wednesday, February 22, 2017 at 11:15:02 AM UTC+3, Saad wrote:

Thanks, it worked very well. However, I am trying the next step in this
logic, and it is not working. I am trying to put the answers of first 2
questions as the options for SELECT_ONE question. The labels are working
fine, but the values submitted to aggregate at the backend are not getting
decoded into the correct variable names. Please see the attached file, and
the snapshot of data submitted on aggregate. I am also encountering
following validation alert, although my logic seems OK.

"ODK Validate Warnings:
Selection choice label text and image uri are both missing for: /dyn/game
choice: 1. Selection choice label text and image uri are both missing for:
/dyn/game choice: 2."

Any suggestions?

On Sunday, 19 February 2017 07:39:02 UTC+5, Geoeng Systems wrote:

Yes, it is possible to reference a variable from a previous question
using the syntax: ${variable}. See sample xlsform attached.

--
Need ODK forms development or training?
www.geoengsystems.com

On Saturday, February 18, 2017 at 4:02:53 PM UTC+3, Saad wrote:

Hi,

Can we reference some data entered as answer, into next questions?
Example: Q1 asks for name. When one enters it (Mike), the next question
says his name as part of question (Dear Mike, what is your address?). Is it
possible in ODK, and how?

Regards,

Saad

It's complicated.

XLSForm provides some "syntactic sugar" to make the XML go down easier.
One of these is the ${fieldname} construct. That doesn't exist in the
underlying XML XForms specification.

XLSForm also scans all displayed text and, in this specific case, all
choice labels, to expand this syntactic sugar into what is needed in the
XML to reference the value stored within that fieldname.

But, this scanning is only done to displayed text. And, elsewhere, the
${fieldname} construct is only replaced with the appropriate XML construct
in the constraint, calculate and required columns of the survey sheet.
i.e., no processing is done on the choice name, which is the value passed
through to ODK Aggregate when a choice label is selected.

The resulting XML file produced by XLSForm contains this definition of the
select-one:

<select1 ref="/dyn/game">
  <label>Which of the 2 games you like more?</label>
  <item>
    <label><output value=" /dyn/game_1 "/></label>
    <value>${game_1}</value>
  </item>
  <item>
    <label><output value=" /dyn/game_2 "/></label>
    <value>${game_2}</value>
  </item>
</select1>

You can see that the "${game_1}" from the choice label is expanded to the
proper XML term:

But the choice name "${game_1}" is copied verbatim into the term.

··· =============== There is no construct within the ODK Collect implementation of XForms to do what you want. The best you can do is have the select-one have fixed terms for the value, e.g., "g1" and "g2". And then have one or two calculated fields (e.g., "most_liked_g", "least_liked_g") that compute the name of the game you liked most and least, then in subsequent questions reference these game names in display text via ${most_liked_g} or ${least_liked_g}, as appropriate.

In your processing of the collected information, use the ${game} field and
the "g1", "g2" to map back to whichever game was most or least liked (or
just use the ${most_liked_g} and ${least_liked_g} fields).

On Wed, Feb 22, 2017 at 5:48 AM, Geoeng Systems info@geoengsystems.com wrote:

This may not be possible in the current toolset. It probably has something
to do with when the model in xml is validated, and therefore you cant use
variables as choice names.

Mitch or Yaw can elaborate further on why this is not possible, and if
there is any plan to make it possible.

--
Need ODK forms development or training?
www.geoengsystems.com

On Wednesday, February 22, 2017 at 11:15:02 AM UTC+3, Saad wrote:

Thanks, it worked very well. However, I am trying the next step in this
logic, and it is not working. I am trying to put the answers of first 2
questions as the options for SELECT_ONE question. The labels are working
fine, but the values submitted to aggregate at the backend are not getting
decoded into the correct variable names. Please see the attached file, and
the snapshot of data submitted on aggregate. I am also encountering
following validation alert, although my logic seems OK.

"ODK Validate Warnings:
Selection choice label text and image uri are both missing for: /dyn/game
choice: 1. Selection choice label text and image uri are both missing for:
/dyn/game choice: 2."

Any suggestions?

On Sunday, 19 February 2017 07:39:02 UTC+5, Geoeng Systems wrote:

Yes, it is possible to reference a variable from a previous question
using the syntax: ${variable}. See sample xlsform attached.

--
Need ODK forms development or training?
www.geoengsystems.com

On Saturday, February 18, 2017 at 4:02:53 PM UTC+3, Saad wrote:

Hi,

Can we reference some data entered as answer, into next questions?
Example: Q1 asks for name. When one enters it (Mike), the next question
says his name as part of question (Dear Mike, what is your address?). Is it
possible in ODK, and how?

Regards,

Saad

--
--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Reviving this thread because it was linked to from How to return the answer of a question to another question.

@Saad in this specific case I would recommend making the values for your choices the literal values 1 and 2 or something like game1 and game2. That will work any time you have a fixed set of choices you want the user to choose from.

If the number of choices isn't known ahead of time (e.g. it comes from a repeat), you can make a small modification to the XML as described here.