Survey123 Conditional/Required/ReadOnly/Relavant - Trickery

2546
5
12-13-2019 02:14 PM
DylanHarwell2
New Contributor

Hi all S123 users!

I am in need of some xlsforms trickery. I am building a survey for a client trying to replicate an old dinosaur of a desktop application they are using to manage some land assets that has very specific business logic associated with some fields..

There are 2 problematic fields I need a solution for at the moment, a Total_Cost field and a Cost_PerArea field. The application does calculations on the back-end using the area of a polygon feature, and the user must only enter a value for one of these fields and then the other gets calculated. For example, a user could enter the cost per area and then the total cost would get calculated by multiplying the polygon area, or on the flip side a user could enter the total cost and then the cost per area would be calculated by dividing the polygon area. Pretty straightforward. 

So the business logic the survey needs to replicate is:

- both fields visible initially

- one has to be required

- if one gets a value the other must become either read-only or disappear (I can use an if statement in the readonly column for one of the fields, but not both at the same time, I get a broken parser error otherwise I think that would be the solution)

Any help would be greatly appreciated!

0 Kudos
5 Replies
DylanHarwell2
New Contributor

Why is it that I cant have an if statement in both field readonly columns, something like:

if(${Planned_Total_Cost},'','yes')

if(${Planned_Cost_PerArea},'','yes')

And similarly in the required column except with the 'yes','' switched. That would solve the problem I believe. If I use one of those if statements for either total cost or cost per area in both required and readonly fields I can get the desired behavior for the other field, but it seems S123 can't handle both at the same time!

Attached is the error I get which is odd because it mentions two fields, relevant and calculate which I am not using.. 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Try not using the yes part.  You can just do ${Planned_Total_Cost} = ''.  If it is a number field you have to test string-length = 0 instead of ''.

I would then hide whichever one you are not using.  I would have to see the form to know on the dependency cycle.  

0 Kudos
DylanHarwell2
New Contributor

The problem with hiding the field is that we don't know which one the user is going to be filling out ahead of time so they both need to be visible. Can an if statement work in the appearance field?

I tried your suggestion, it's not a syntax issue because all the statements I've tried work on one field, but as soon as I put it in both fields it breaks. 

Here is a test form I've been experimenting on. 

Basically both fields should be visible and required when the form loads, as soon as a value is entered in one of the fields, the other needs to become not required and either hidden or read-only. And like I said it works if I only have that logic implemented on one of the fields I get the desired behavior with the other, but it seems like it can't handle it on both.

0 Kudos
DougBrowning
MVP Esteemed Contributor

You did not attach anything.

But if you are trying to do If field A in field B and then also a if field B in field A then yes this is a redundancy loop.  This means an endless loop of checking would occur.  Field A checks B and changes, which fires a change in B, which fires a change in A, and on and on.  

If you post the form maybe we can figure out some other logic.

0 Kudos
DylanHarwell2
New Contributor

It's attached to the original question at the top..

0 Kudos