Dear all,
the possibilities in Survey123 Connect are really great.
Unfortunately sometimes the syntax is not easy.
In my form I have the following challenge.
People have to fill out EITHER the text-field "tax-id"
or the text-field "Company-tax-id".
I try to solve it via constraints.
My question is:
Is it possible to create "IF" or "OR" constraints?
So far I have an regular-expression-constraint for the tax_id-field (regex(., '^\d{11}$'))...
but I need a constraint-solutions that checks:
a) Are the fields "tax-id" AND "Company-tax-id" empty? (not allowed, if they both are empty a constraint-message should appear)
AND
b) Is the syntax of a tax-id correct (regex(., '^\d{11}$')) (ok, for that I have a solution)
AND
c) allows the text-string "Not existing" (but only for ONE of the two fields)
Could anybody give me a hint how to solve that? If a) + b) +c) is too difficult I would be happy also about a solution for a) + b) 🙂
Thank you very much, Kai
Solved! Go to Solution.
If found a solution now. I work with different note-sections and calculations:
Note for tax_id_field:
Calculation: if((regex(${steuer_id} , '^\d{11}$') or ${steuer_id}='Nicht vorhanden'), 'OK', 'FALSCH')
Note for company_tax_id_field:
Calculation: if((regex(${wirtschaftlichkeitsnummer} , '^DE\d{9}$') or ${wirtschaftlichkeitsnummer}='Nicht vorhanden'), 'OK', 'FALSCH')
extra note that checkes circumstances:
Calculation:
if(((${wirtschaftlichkeitsnummer}='' and ${steuer_id}='' and ${plz}!='')or (${wirtschaftlichkeitsnummer}='Nicht vorhanden' and ${steuer_id}='Nicht vorhanden' and ${plz}!='') or (${wirtschaftlichkeitsnummer}='Nicht vorhanden' and (not(regex(${steuer_id} , '^\d{11}$')))and ${steuer_id}!='Nicht vorhanden') or (${steuer_id}='Nicht vorhanden' and (not(regex(${wirtschaftlichkeitsnummer} , '^DE\d{9}$')))and ${wirtschaftlichkeitsnummer}!='Nicht vorhanden')),'WRONG','OK')
And then I putted constraints to the tax_id_field:
${eingabe_steuer_wirtschaft}=‘OK’ and (${testfeld_a}=‘OK’ or ${testfeld_b}=‘OK’)
and the same constraint for the company_id_field:
${eingabe_steuer_wirtschaft}=‘OK’ and (${testfeld_a}=‘OK’ or ${testfeld_b}=‘OK’)
Everything fine 🙂
This can be done, but it looks a little inefficient.
Firstly, I'd avoid the whole "Not existing" option. It's unnecessary, since it's just another way of stating that the field is null. It's also possible for it to be inaccurate. A client may well have a company tax ID and choose to use their personal ID or vice versa, so that data exists, you just haven't collected it. It also means that users are being prompted to fill in both fields even though you won't allow them to do that. An finally, it means that if the user makes a typo, the field won't submit, but it won't be obvious why.
What I've done in the second example is to start by asking the user what tax ID they wish to use. They can't proceed until they select one, and they can only enter a number for the one they select. This makes the survey clearer, and makes the "not existing" field unnecessary.
If the "Not existing" option is meant to be a placeholder to enable the user to register that this survey is linked to a is a business tax number, but the number isn't available or some reason, then you're far better off having another select-one yes-no question after asking the tax-id type question. If the person selects "no" that means "Not existing" and they are not asked to fill in the number. If you really must, you can then autopopulate the (now hidden) tax id number field with "Not existing". That produces the result that you require, but without needing to enter the text and make errors. It's also much clearer to the user.
There are similar issues with checking to see if both fields are empty. This points to the fact that the user is seeing both fields when only one is required. Much clearer an simpler to start your survey by asking the user two questions: "Which tax id do you want to to use (company/private)" and "Is the id number available". ON the basis of those questions a single field for entering a number is visible, and you can then evaluate whether the format is correct. No need to evaluate whether both fields are empty. No frustration for user caused by a answering both visible questions, even though they are only allowed to answer one.
In the attached example, I've replaced your regex expression with "test" for testing purposes. You should be able to just in your own. Remember that a regex looks for a pattern, not a length. You probably want to add a string-length constraint as well, to prevent additional characters at the start or end of the tax-id.
If found a solution now. I work with different note-sections and calculations:
Note for tax_id_field:
Calculation: if((regex(${steuer_id} , '^\d{11}$') or ${steuer_id}='Nicht vorhanden'), 'OK', 'FALSCH')
Note for company_tax_id_field:
Calculation: if((regex(${wirtschaftlichkeitsnummer} , '^DE\d{9}$') or ${wirtschaftlichkeitsnummer}='Nicht vorhanden'), 'OK', 'FALSCH')
extra note that checkes circumstances:
Calculation:
if(((${wirtschaftlichkeitsnummer}='' and ${steuer_id}='' and ${plz}!='')or (${wirtschaftlichkeitsnummer}='Nicht vorhanden' and ${steuer_id}='Nicht vorhanden' and ${plz}!='') or (${wirtschaftlichkeitsnummer}='Nicht vorhanden' and (not(regex(${steuer_id} , '^\d{11}$')))and ${steuer_id}!='Nicht vorhanden') or (${steuer_id}='Nicht vorhanden' and (not(regex(${wirtschaftlichkeitsnummer} , '^DE\d{9}$')))and ${wirtschaftlichkeitsnummer}!='Nicht vorhanden')),'WRONG','OK')
And then I putted constraints to the tax_id_field:
${eingabe_steuer_wirtschaft}=‘OK’ and (${testfeld_a}=‘OK’ or ${testfeld_b}=‘OK’)
and the same constraint for the company_id_field:
${eingabe_steuer_wirtschaft}=‘OK’ and (${testfeld_a}=‘OK’ or ${testfeld_b}=‘OK’)
Everything fine 🙂