Not able to get the label in calculate field

Hello team,

I am trying to fetch the label name of the option selected using jr:choice-name() function. But some how I see an error message once the form get updated in enketo - “FormLogicError: Could not evaluate: if( /model/instance[1]/aGx9ykmJP6iFxDeuog56uF/C1 =01, “”, jr:choice-name( /model/instance[1]/aGx9ykmJP6iFxDeuog56uF/C2 ,’ /aGx9ykmJP6iFxDeuog56uF/C2 ')), message: Function “{http://openrosa.org/javarosa}choice-name” does not exist.”

Consider an example - where you have set of single select questions

  • Question : C1
  • Option 1 – 01
  • Option 2 – 02
  • Question : C2
  • Option 3 – 03
  • Option 4 – 04
  • Question : C3
  • Option 5 – 05
  • Option 6 – 06
    In the calculate field if I use if(${C1}=01, jr:choice-name(${C2},'${C2}'), jr:choice-name(${C3},'${C3}') ). This is to get label of C2 if C1 is ‘01’ else get the label of C3. This is not working in kobo.

The expression ` if(${C1}=01, jr:choice-name(${C2},’${C2}’), ${C3} ) works - But in this case I am not able to fetch the label of C3 question.

Any solution over this?

Regards,

Amar

Hey Amar

Seems highly likely that it is this issue:

I'll patch my local install Tonite and see if it fixes the issue

Lobo

hey amar:

some further experiments and a hackish work-around:

  1. applying the patch referenced above did not seem to work nicely. I could not find instructions on how to patch a file and deploy it, ran into quite few issues.

  2. Seems like it was committed in github, i followed the kobotoolbox docker images (on hub.docker.com) and realized that there were recent versions of enkety, i cho_express

Specifically, i changed the docker compose file to:

image: kobotoolbox/enketo-express-extra-widgets:1.61.4

kobotoolbox folks: not sure why there is no tag for latest for that specific docker image

  1. Unfortunately that did not seem to fix the problem, I did verify the patched file was there. I’ll follow up on the enketo-express issue tracker

  2. as a workaround, you can do the following:

a. C4 = if(${C1}=01, jr:choice-name(${C2},‘${C2}’), ‘’ )

C5 = if(${C1}=02, jr:choice-name(${C3},‘${C3}’), ‘’ )

C6 = concat(${C4}, ${C5})

not great, but is not a blocker

from a larger perspective, it does not seem right that for C1/C2/C3 you are storing values, but for C4/C5/C6 you want to store labels. It might be useful to be consistent across the entire form

lobo

···

On Thursday, March 15, 2018 at 1:25:22 PM UTC-7, Donald Lobo wrote:

Hey Amar
Seems highly likely that it is this issue:

https://github.com/enketo/enketo-core/issues/490

https://github.com/enketo/enketo-core/pull/493

I’ll patch my local install Tonite and see if it fixes the issue

Lobo

Thanks Donald for the workaround.

Regards,
Amar

···

On Friday, March 16, 2018 at 7:07:38 AM UTC+5:30, Donald Lobo wrote:

hey amar:

some further experiments and a hackish work-around:

  1. applying the patch referenced above did not seem to work nicely. I could not find instructions on how to patch a file and deploy it, ran into quite few issues.
  1. Seems like it was committed in github, i followed the kobotoolbox docker images (on hub.docker.com) and realized that there were recent versions of enkety, i cho_express

Specifically, i changed the docker compose file to:

image: kobotoolbox/enketo-express-extra-widgets:1.61.4

kobotoolbox folks: not sure why there is no tag for latest for that specific docker image

  1. Unfortunately that did not seem to fix the problem, I did verify the patched file was there. I’ll follow up on the enketo-express issue tracker
  1. as a workaround, you can do the following:

a. C4 = if(${C1}=01, jr:choice-name(${C2},‘${C2}’), ‘’ )

C5 = if(${C1}=02, jr:choice-name(${C3},‘${C3}’), ‘’ )

C6 = concat(${C4}, ${C5})

not great, but is not a blocker

from a larger perspective, it does not seem right that for C1/C2/C3 you are storing values, but for C4/C5/C6 you want to store labels. It might be useful to be consistent across the entire form

lobo

On Thursday, March 15, 2018 at 1:25:22 PM UTC-7, Donald Lobo wrote:

Hey Amar
Seems highly likely that it is this issue:

https://github.com/enketo/enketo-core/issues/490

https://github.com/enketo/enketo-core/pull/493

I’ll patch my local install Tonite and see if it fixes the issue

Lobo