If statement for NFC tag and type hidden question type

I use NFC fonctionality in a form to read a card (student card)
and a form field are automaticaly filled with the tag NFC ,it works fine.

aaa

Explanation of the form:
When a student card read by NFC , fields are automaticaly filled, category field (note type) can take two values ( CATEG_A or CATEG_B) according to the student card :

  • if Category = CATEG_A : select_one Science is checked

  • if Category=CATEG_B : select_one Literature is checked
    for this here is my formula if((${Category} = ‘CATEG_A’),‘science’ ,if((${Category} = ‘CATEG_B’),‘literature’,’’))
    however the Category field from the tag is not very relevant because of the tag name : CATEG_A or CATEG_B
    so I use hidden type for Category field but the form not work anymore because in the select_one Faculty select_one Science or select_one Literature is not checked.

How to fix this problem.
thank you in advance.
Excuse my english

1 Like

Hi @evariste,

Welcome back to the community! Seems like you have an issue with the if statement. Try out the following and it should work for you:

if((${Category}=‘CATEG_A’),‘science’,if((${Category}=‘CATEG_B’),‘literature’, ‘’))

As a workaround you could also have a look at the image shared below:

In the survey tab of your xlsform:

In the choices tab of your xlsform:
Image 102

Data entry screen as seen in Enketo:

Reference xlsform:
If Statement.xlsx (10.4 KB)

For further learning you could also have a look at our support article ADVANCED USE OF CALCULATE QUESTIONS.

You could also have a look at some of our workarounds discussed earlier here.

Have a great day!

1 Like

Hi @Kal_Lam,
thank for reply me.
You didn’t understand me,my If statements works fine. As I said, the radio button in faculty field is checked depending on the value set in category (type note ). The issue is that when I use the hidden tag on the category (type note ) field to hide it, it seems that it’s value is no longer available, therefore my if statement do not work fine. the value of category is set automatically by the program depending on the value returned by the NFC .

Hi @evariste,

If this is the case, isn’t it possible to change the hidden variable with the select_one. It should solve your issue.

Have a great day!

1 Like

Hi @Kal_Lam, Thanks
The hidden variable must not modify with the select_one because its receive automaticaly data from NFC

the issue is : how to use variable of hidden type in other type?

Hi @evariste,

Maybe you could exploit the hidden question type with calculation to achieve your requirement as outlined in the image below:

In the survey tab of your xlsform:

Image 1

Data entry screen as seen in Enketo:

Reference xlsform:

Hidden & Note Questions.xlsx (9.5 KB)

Have a great day!

Hi @Kal_Lam,

My hidden variable is the string type and when I use a string variable with calculate ,I have an error.

1 Like

Hi @evariste,

If you wish to use the string within a calculation then you could do the same using the concat() as outlined in the image below:

In the survey tab of your xlsform:

Image 1

Data entry screen as seen in Enketo:

Reference xlsform:

Hidden & Note Questions.xlsx (9.5 KB)

Have a great day!

1 Like