# Can we write two logic together

Hi Team,

Can we write two logic together in constraint column?

Q105 :-

• Condition - not(\${Q103} =3 and . !=7) - Error Msg "If Sex code is 3 than Marital Status code should be 7 (NOT APPLICABLE). Check the Sex of respondent".
• Condition - (\${Q104} <=3 and . = 5) or \${Q104} > 3 - Error Msg " If Age is less then or equal to three than Marital Status code should be 5 (Never Married). Check the Age of the respondent."

I am enclosing the xlsx form and marked my query question in Yellow colour.Anil-Sample07-export.xlsx (18.8 KB)

Thanks & regards,

Anil

Hi @AnilRawat
of course it's possible even in the doc you can find some simple expressions with and https://docs.getodk.org/form-logic/
If you need something more complex, maybe the form I attached in this post Constraint the answers based on previous answer

You just need to remember than constraints are not evaluated if the response is left blank, so if in such a column you check answers from previous questions the current one also must be answered.I don't fully understand why and I reported that long time ago https://github.com/getodk/javarosa/issues/327

Hi Grzesiek,

Can you please do me a favour.

I have written a command against the Q105. Can you please that command. It is not working. Only one command is working other one is not.

I would like to request you please make a correction in excel sheet if possible at your end.

Thanks for your support and guidance.

Thanks & regards,

Anil

If Sex code is 3 than Marital Status code should be 7 (NOT APPLICABLE). Check the Sex of respondent. If Age is less then or equal to three than Marital Status code should be 5 (Never Married). Check the Age of respondent.

The expression would be `(\${Q103}!=β3β or . =β7β ) and (\${Q104}>3 or . =β5β)`. Please try it out and let me know.

1 Like

Hi Grzesiek,

Sure, I will check this command and get back to you soon.

Thanks for your support and guidance.

Thanks & regards,

Anil

Dear Grzesiek,

I have checked the below command second command is working but the first one is not working. i have marked command in bold letter.

1. If Sex code is 3 than Marital Status code should be 7 (NOT APPLICABLE). Check the Sex of the respondent.

2. If Age is less then or equal to three than Marital Status code should be 5 (Never Married). Check the Age of the respondent.

(\${Q103}!=β3β or . =β7β ) and (\${Q104}>3 or . =β5β).

Thanks & regards,

Anil

Dear Grzesiek,

I have checked the below command second command is working but the first one is not working. i have marked command in bold letter.

If Sex code is 3 than Marital Status code should be 7 (NOT APPLICABLE). Check the Sex of the respondent.

not(\${Q103} =3 and . !=7)

If Age is less then or equal to three than Marital Status code should be 5 (Never Married). Check the Age of the respondent.

((\${Q104} <=3 and . = 5) or \${Q104} > 3)

Individual the above commands are working but together second is working but the first one is not working.

Thanks & regards,

Please attach you form with that expression I need to check if you use it correctly.

Dear Grzesiek,

Please find enclosed the xlsx form. I have marked that question in yellow colour.

Thanks for your support and guidance.

Thanks & regards,

AnilAnil-Sample07-export.xlsx (18.9 KB)

So it's not the expression I prepared for you, you have:
`not(\${Q103} =3 and . !=7) and ((\${Q104} <=3 and . = 5) or \${Q104} > 3)`
but mine was:
`(\${Q103}!=β3β or . =β7β ) and (\${Q104}>3 or . =β5β)`

why do you use that `not`?

Dear Grzesiek,

I have used this as well this also not working. I have written in my previous mail as well. First Bold command is not working.

(\${Q103}!=β3β or . =β7β ) and (\${Q104}>3 or . =β5β)

1. If Sex code is 3 than Marital Status code should be 7 (NOT APPLICABLE). Check the Sex of the respondent.

2. If Age is less then or equal to three than Marital Status code should be 5 (Never Married). Check the Age of the respondent.

Thanks & regards,

Anil

I was on leave and couldn't respond. Were you able to fix your problem or you still need help?

(\$ {Q103}! = '3' hoαΊ·c. = '7') Q105 CHOICE (seclect not 7)