Dear users,
in my Survey123 Connect I want, that an error message appears if a specific values is > 4000.
That works quite good. I do a calculation for a "note-field" under the input fiels like: "if((${erg23} >4000),'WRONG','OK')"
But:
In my form people can open an addition calculation field, if the select a multiselection field:
At the end of the day I want to have a calculation like "if(((${erg23} + ${erg23a})>4000),'WRONG','OK')", so that the first value + "the sometimes values" are checked, if they are higher > 4000.
Well., that works, if both fields get a value:
But ""if(((${erg23} + ${erg23a})>4000),'WRONG','OK')"" does not work at all, if the second field is not integrated. Even if I put then "6000" in the first field (obviously > 4000) I dont`t get a Wrong-message. What can I do to add values to a calculation of fields, that only sometimes appear?
I need something like: "if(((${erg23} + if isset(${erg23a}=)>4000),'WRONG','OK')".
Has anybody an idea?
Solved! Go to Solution.
When erg23a is not relevant, it has no value. Trying to do math on a no value field is what is causing issues in your calculation. You need to account for this and provide a value of 0 in your calculation.
if((${erg23} + if(string-length(${erg23a}) > 0, ${erg23a}, 0)) > 4000, 'Wrong', 'OK')
This calculation uses string-length to determine if erg23a has a value, if so, use the erg23a value, if not use 0 in your addition.
When erg23a is not relevant, it has no value. Trying to do math on a no value field is what is causing issues in your calculation. You need to account for this and provide a value of 0 in your calculation.
if((${erg23} + if(string-length(${erg23a}) > 0, ${erg23a}, 0)) > 4000, 'Wrong', 'OK')
This calculation uses string-length to determine if erg23a has a value, if so, use the erg23a value, if not use 0 in your addition.
Thank you very much, that is a nice solution.