IF Statements with calculationMode (Change mode based on Current User)

123
2
2 weeks ago
RobertAnderson3
MVP Regular Contributor

I haven't dug into it yet but I'm putting it out there for suggestions, I think it's more possible than I initially thought, but I also wanted to share to make sure people knew:

In the bind::esri::parameters column I've learned you can use if statements, which is wonderful. Such as: if(${ActivityCode}!='other','calculationMode=always','calculationMode=whenEmpty')

We have workflows that involve field users collecting data, and then sometimes an office user will update if there is a mistake. I have a handful of questions set with calculationMode=always to make sure the final value is always accurate as in the past things have gotten disconnected.

However, due to an if statement requiring an else I have some like if(${vehicle}!='Other',${vehicle},'') which when the office user goes to edit it means the previously entered value is cleared.

I do this to put the value in a single field to make Automate/reporting easier later.

Do we think I could change it to not calculate if the office user is the account signed into Survey123?

2 Replies
abureaux
MVP Regular Contributor

In the bind::esri::parameters column I've learned you can use if statements,

Good to know!

Honestly, I'm not clear what operation the office worker is doing that causes the field to be empty.

However, when it comes to "other" fields where the selection is a select_one, I am going with the 3-field approach. First is the select_one, second is the conditional other field, and third is a calculate I use in outputs set up as, for example, coalesce(${vehicle_other},${vehicle}). If the other field contains data, the coalesce() will contain the other text. If the other field is empty (thanks to the relevant column), it defaults to the main select_one.

0 Kudos
RobertAnderson3
MVP Regular Contributor

It's because of how I have this question set up, the calculationMode=always causes it to run the calculation and return the '' because 'Other' is still selected.

namecalculationbind::esri:parameters
vehicle  
otherVehicleif(${vehicle}!='Other',${vehicle},'')calculationMode=always

 

I wish the if could just be if(${vehicle}!='Other',${vehicle}) and do nothing if not true, but it can't. I have the 3 field approach used in some surveys, I was just trying to be clever and use fewer fields, which worked fine until editing came into play haha. I should probably just move to that approach for this question as well.

I have also implemented: 
if(${ActivityCode}!='other','calculationMode=always','calculationMode=whenEmpty') 
in another question and it seems to work fine, for some reason I thought 'nah that won't work for this one' but looking at it again this morning, I'm pretty sure it will. Because it will always calculate when anything that is not 'other' is selected, but if 'other' is selected, it will not run, which effectively nullifies the 'else' of '' being returned ever.