Automatically calculate filed value in odk build

Hi ODK Forum,

Here is my requirement mention on the screenshot below:

Please guide me.

Thanks,

Any replay for this question?

Hi @tasadduq786

The result of the variable worker_CNC_details is the underlying value selected by the user.

I assume you are trying to display the variable chosen. In this you can type:
${worker_CNC_details} in the label field. This way the option chosen in the previous field will be displayed.

To refer a variable by enclosing the DataName of a previous question in the ${} symbols, as per example above. This works also in calculated fields.

I hope this helps!

Best,
Andrea

1 Like

Hi Andrea_Martin,

Thanks for your replay.

My requirement is that when i choose option "Alien" it's auto calculate with word "alien" in "worker_cnic" field and when i choose either "Own,Other,Father,Mother,Brother" it's go/move to other text filed " worker_cnic".

It's also describing in my above mention screenshot.

Regards,

Hi @tasadduq786

There are different possible interpretations to your use case, thus the kind request for clarification.

Can you indicate which of the following scenarios you identify with?

  1. You want to capture the answer to the worker_CNC_details variable (e.g. Own,Other,Father,Mother,Brother, Alien, ...)
  2. You want to display the answer selected at worker_CNC_details in subsequent questions
  3. You only want to ask question worker_cnic if a particular option is selected at worker_CNC_details

For case 1), you don't need to do anything in particular. The answers are automatically saved by ODK collect.
For case 2), please use the syntax ${variable_name} as explained in the previous reply
For case 3), you can use the skip pattern by adjusting the relevant field

Best,
Andrea

Thanks Andrea_Martin,

I have question worker_CNC_details with variable (e.g. Own,Other,Father,Mother,Brother, Alien, ...) and other is worker_cnic.

It's already working when i choose any options (Own,Other,Father,Mother,Brother) it's goto subsequent question (worker_cnic) and manually enter the worker cnic number.

My requirement is that when i choose (Alien) it's auto calculate/filled with "alien" in worker_cnic subsequent question.

Here is xml:

1.xml (2.9 KB)

I am using ODK Build v0.3.5.

Please see the above xml and write correct syntax.

Regards,

Hi @tasadduq786,

I guess you are in the second scenario I mentioned in a previous reply.
My suggestion would still be to:

Possibly other Forum members have more or different suggestions.

Best,
Andrea

FYI: I have tried to convert the xml file you uploaded with XLSForm online and it threw this error.
Error: File was not recognized

Thanks your very much.

Please have a play with the following form in XLSForm Online and see if it behaves as you desire:

cnic.xls (19 KB)

Or here's the XML if you want to try it in Collect:

cnic.xml (1.6 KB)

The 'secret sauce' is the Worker_CNIC calculation:

once(if(/cnic/Worker_CNC_Details='Alien', 'alien', ''))

Which will pre-fill a response of 'alien' when you choose Alien in the previous select_one, but if you choose something else nothing gets pre-filled. Please note, this only happens once (hence the function name...), so if choose something else, then manually fill in Worker_CNIC, then go back and select Alien it will not get prefilled again. That's a fundamental limitation of this approach, but its probably the best you can do for now. See once() for details.

BTW, as noted by @Grzesiek2010 and @Andrea_Martin , ODK Build has a custom form format and isnt commonly used, so getting help with ODK Build forms will likely take you much longer... But hopefully it is obvious from my above explanation, and XML form, what change you need to make to your ODK Build form to implement the same.

1 Like

Hi,

I have question worker_CNC_details with variable (e.g. Own,Other,Father,Mother,Brother, Alien, ...) and other is worker_cnic.

It's already working when i choose any options (Own,Other,Father,Mother,Brother) it's goto subsequent question (worker_cnic) and manually enter the worker cnic number.

My requirement is that when i choose (Alien) it's auto calculate/filled with "alien" in worker_cnic subsequent question.

Here is xml:

1.xml (2.9 KB)

I am using ODK Build v0.3.5.

Please see the above xml and guide me.

Regards,

Any guide please.Advance Thanks.

ODK Forum,

I have question worker_CNC_details with variable (e.g. Own,Other,Father,Mother,Brother, Alien, ...) and other is worker_cnic.
It's already working when i choose any options (Own,Other,Father,Mother,Brother) it's goto subsequent question (worker_cnic) and manually enter the worker cnic number.
My requirement is that when i choose (Alien) it's auto calculate/filled with "alien" in worker_cnic subsequent question.Using ODK Build v0.3.5.

Advance Thanks

Regards,

Dear ODK Forum,

My requirement is below:

If option "Own,Father,Mother,Brother,Other" is chosen from list text filed named "Worker CNIC" open and i fill this text filed and if option "Alien" is choose from list,then text field named "Worker CNIC" not open.
I am using ODK Build.here is screenshot.


Please guide me.

Advance Thanks,
Regards,

Hi @tasadduq786

  1. Click on the second question.
  2. Expend advanced options.
  3. In Show question if add /data/worker_CNIC_details!='Alien'

but generally I would recommend using xls to create forms, maybe it seems a bit more difficult at the beginning but it gives more options.

Thanks Grzesiek2010,

Please tell me where i putt "add /data/worker_CNIC_details!='Alien'" in either worker_CNIC_details or in worker_CNIC?

Regards,

The second question which is worker_cnic

Not working.

Could you attach the xml file?

Here is xml file.

Issue.xml (2.6 KB)

It's working fine for me, the second question is not displayed if you selected Alien isn't it what you expected?