Automatically calculate filed value in odk build

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?

it's working fine but in this xml not working properly.

22.xml (80.2 KB)

please see it.

Look at these two lines:

  <bind nodeset="/data/Worker_detail/worker_CNIC_details" type="select1" required="true()"/>

  <bind nodeset="/data/Worker_detail/worker_cnic" type="string" required="true()" relevant="(/data/worker_CNIC_details != 'Alien')" constraint="(regex(.,'^[0-9]{5}-[0-9]{7}-[0-9]{1}$'))"/>

if the path of worker_CNIC_details is /data/Worker_detail/worker_CNIC_details your expression below should be:
(/data/Worker_detail/worker_CNIC_details != 'Alien') not (/data/worker_CNIC_details != 'Alien')

as I said above, try to use xls instead otherwise it will be super difficult when you will need to create complex forms.

Thanks Grzesiek2010,

I really appreciate your guidance.Now,it's working fine.

I want to know and guide me that::

If Alien is selected then it's possible that automatically entered/filled word "Alien" in "worker_cnic" filed.

Regards,

No it's not possible because we don't support dynamic default answers please read Assigning a dynamic default value to a text-type question
You can do something like described int this asnwer Assigning a dynamic default value to a text-type question - #2 by yanokwa

Thanks Xiphware.

I am very grateful to you.

YW. If you’ve found a satisfactory resolution please mark the thread as solved, thanks.