I'm working on a survey that calculates the value radius based on a diameter value that changes depending on another part of the form. In Survey123 Connect on Windows the first scenario works but it does not work on a web form. The second scenario works in both Windows and the web. Should the first one work in both places?
It appears the inner parentheses is always evaluated to 1 in scenario 1, regardless of the terms.
variables
decimal DIAMETER_ROUND set to 5.5
decimal HORIZONTAL is null and hidden by relevancy
formula
double RADIUS calculate (${DIAMETER_ROUND} or ${HORIZONTAL}) div 2
results
Windows: 2.75 (correct)
Web form: 0.5 (wrong)
variables
decimal DIAMETER_ROUND set to 5.5
decimal HORIZONTAL is null and hidden by relevancy
formula
double RADIUS calculate if(${PIPE_SHAPE}="round",${DIAMETER_ROUND} div 2,${HORIZONTAL} div 2)
result
Windows: 2.75 (correct)
Web form: 2.75 (correct)
Solved! Go to Solution.
Hi Elliott,
I don't think I would expect the first formula to work properly - the part
(${DIAMETER_ROUND} or ${HORIZONTAL})
creates a true/false comparison. In the interpreter used by the field app, this yields the first non-null value (a quirk of javascript). The web form adheres to a more strict definition and returns true or false only - in javascript, this gets converted to 1 or 0 for the division step.
Hi Elliott,
I don't think I would expect the first formula to work properly - the part
(${DIAMETER_ROUND} or ${HORIZONTAL})
creates a true/false comparison. In the interpreter used by the field app, this yields the first non-null value (a quirk of javascript). The web form adheres to a more strict definition and returns true or false only - in javascript, this gets converted to 1 or 0 for the division step.
Yea i agree. You can test the fields to see if they are hidden using ''.
So
if(${DIAMETER_ROUND} != ''; ${DIAMETER_ROUND} div 2, ${HORIZONTAL} div 2)
Just like your second statement.
Thanks. Does the '' test work on integers or float/double variables?
yep i think so