Odk 2.0 survey csv queries assign to use in conditional logic

Is it possible to use csv query result in an assign statement for use in conditional logic?

If a csv query is created in the queries sheet and named csvquery1
and the csv is as follows for example:

key data1 data2 data3 data4 data5....dataN (HeaderROW)
1 someVal1 ...... SomeValn
2
3 someVal3 .......SomeOtherValN
etc......

Can I assign a variable using some javascript based on key?

e.g. something like (psuedocode) -

assign myData1 = csvquery1[KEY].data1

to then use later in some conditional e.g. if myData1 === blah

If so is there any example doing something similar?

Thanks,
tom

One thing that you can do is create a select_one prompt that will use the
result of your query to populate the values_list of this prompt. You can
then use a choice_filter on this prompt to limit the selection to one value
if you want. This selected value could then be used in a conditional.

I've attached an example xlsx file and csv file. If the user puts in an
envelope number of 1, the select_one prompt will only display the "SOC"
choice. When the user selects this, the conditional evaluates to true and
displays the note "You chose Standard Of Care".

Clarice

rerand_failure.xlsx (13.9 KB)

S2a-test.csv (279 Bytes)

··· On Sun, Sep 27, 2015 at 7:05 AM, <7shriner@gmail.com> wrote:

Is it possible to use csv query result in an assign statement for use in
conditional logic?

If a csv query is created in the queries sheet and named csvquery1
and the csv is as follows for example:

key data1 data2 data3 data4 data5....dataN (HeaderROW)
1 someVal1 ...... SomeValn
2
3 someVal3 .......SomeOtherValN
etc......

Can I assign a variable using some javascript based on key?

e.g. something like (psuedocode) -

assign myData1 = csvquery1[KEY].data1

to then use later in some conditional e.g. if myData1 === blah

If so is there any example doing something similar?

Thanks,
tom

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

Hi Clarice,

When I used the same query, XLSX converter threw the below error -

Error: Error: Unexpected token & interpretting formula: _.map(context, function(place){ place.data_value=place.monthname; place.display = {text:place.monthname}; return place; }) on sheet: queries row: 4 column: callback

Screenshot of the queries worksheet is below -
image

Screenshot of months_of_year.csv file -
image

Appreciate your help!
Cheers.

Hi Satish,

The syntax used in this example is outdated. I have included a csv file months_of_year.csv (142 Bytes) and xlsx file months.xlsx (12.4 KB). I've verified that it works in the Application Designer. Hopefully, this example should work to accomplish what you are looking to do. If you find another issue, let us know.

Thanks,
Clarice

2 Likes

Thanks, Clarice!
Worked like a charm.

2 Likes