Select to view content in your preferred language

If/Then/Else in Connect Issue

164
3
a week ago
WindsorConnecticut
Occasional Contributor

I'm trying to create a seemingly simple calculation to a field in Survey 123 Connect, but I'm having issues with the syntax. 

I want this field to calculate whether or not the previous entries in the same form match. The 'parent_add' is auto populated but the 'siteadd_og' is manually entered. I've tried several iterations of this same equation and they have either failed when converting to the survey itself, or converted with no issue, but then did not function in the survey itself. I've definitely seen examples of this operating with other types of data and simpler calculations, like take the number from question 2 and multiply by 100, which updates live in the form, but I can't seem to replicate this for this scenario. 

My enterprise is on version 10.9.1 and Survey 123 is 3.20. I also had issues hiding this question even though I set the visibility to 'hidden' in the excel form. 

So far I've tried many versions of this but here are two in the "Calculation" coulmn: 

1. if(selected(${siteadd_og} = selected(${parent_add})), 'No', 'Yes')

>>will not convert to the survey

2. if(${siteadd_og} = ${parent_add}, 'No', 'Yes')

>>will convert to survey, but does not function in the form. 

 

Can anyone help me out with this? Please?

0 Kudos
3 Replies
clt_cabq
Frequent Contributor

in the first statement, are you missing a closing parenthesis for the If? 

0 Kudos
MobiusSnake
MVP Regular Contributor

The second one looks fine but it's unclear what you mean by "does not function in the form".  Can you post the XLSX?  There could be issues stemming from outside of the if statement.

0 Kudos
abureaux
MVP Frequent Contributor

"I also had issues hiding this question even though I set the visibility to 'hidden' in the excel form"

I believe "hidden" is overridden by the "relevant" and "body::esri:visible" columns. Check for something in those columns.

1. if(selected(${siteadd_og} = selected(${parent_add})), 'No', 'Yes')

>>will not convert to the survey

This is expected. This equation does not follow proper syntax.

Here are some tips:

  • For SELECTED(), it follows this format selected(<field_name>, '<result>'). In your example above, this could be a proper use of SELECTED(): selected(${parent_add}, 'No')
    EDIT: I updated the equation above. I copy-pasted from the original equations and missed a bracket.
  • The SELECTED() equation on its own results in true/false. So if you selected "No" for ${parent_add}, then selected(${parent_add}), 'No') = 'False'.
  • SELECTED() also uses the name column, not the label column. So if your yes/no field is set up like the screen cap below, your SELECTED() equation should look like this: selected(${parent_add}, 'no')
    abureaux_0-1727208240456.png
  • For IF(), it follows this format if(<logical test>, <value if true>, <value if false>). In your example above, this could be a proper use of IF(): if(${siteadd_og} = ${parent_add}, 'Yes, 'No')

2. if(${siteadd_og} = ${parent_add}, 'No', 'Yes')

>>will convert to survey, but does not function in the form.

This is proper syntax. Worst case scenario, it should always result in "Yes". If the "No" option isn't working, then the data you are comparing isn't the same (note that it is caps-sensitive).

 

Any chance you can include your XLSX?

0 Kudos