Survey123 Reset value based on other field conditional

2452
5
Jump to solution
09-21-2020 03:12 PM
MichelleHawks1
New Contributor II

Hello,

I have an integer field that is readonly when a previous select_one yes_no field is 'no'.  The select_one yes_no defaults to 'no'.  When 'yes' is selected the integer field activates and accepts values as intended.  However, if the 'yes' is changed to 'no', the integer field retains the entered value.  I need the field to reset to '0' whenever the yes/no field is set back to 'no'.  Is there any way to force or reset, or build a calculation that sets the value back to '0' on that condition?

Assume:

DevFeature_YN: is the select_one yes_no field

DevFeature_count: is the integer field with readonly when ${DevFeature_YN} = 'no'

So, if DevFeature_YN is set to 'yes' and DevFeature_count is set to 5, then user realizes they are in the wrong field and sets DevFeature_YN back to 'no', how do I reset DevFeature_count back to 0?

I tried a calc statement in the DevFeature_count calculation field, but it had an error: 

   if(${DevFeature_YN} = 'no',0,${DevFeature_count})

I tried a using once(), but it also had an error: 

   if(${DevFeature_YN} = 'no',0,once(${DevFeature_count}))

I tried a the self notation, but it also had an error: 

   if(${DevFeature_YN} = 'no',0,.)

I may be missing something obvious, but am totally at a loss.

Michelle

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

I get what you are saying but as far as I know you cannot do it that way.  There is no way to say calc or leave it alone.  You can try if(set to no, 0, "") but as you will see it will sometimes leave it and sometimes wipe it.

The trick I use is to have 3 fields.  But with using a Grid here it gets a little tougher.  Instead use 2 fields that flip on or off.

Attached is a sample. 

Someone may have another idea.  Hope it helps.

View solution in original post

5 Replies
DougBrowning
MVP Esteemed Contributor

I think you may be seeing two issues.  One is you can't reference a field in itself as it creates a cyclical loop.  So if something do this or just stay the same does not work with the form logic.  The second is when a field goes read only the calcs stop since well it is read only.

One way to handle this is to have a 3rd field that stores the ultimate value.  

Field 1 DevFeature_YN 

Field 2 User input field with a relevant on no for field 2.  Can send bind esri type to null then it will not create a field in the service.

Field 3 Actual stored field with formula if(DevFeature_YN = 'no', 0, Field 2)

Hope that helps

0 Kudos
MichelleHawks1
New Contributor II

First, thanks so much for responding, Doug.  I'm sorry I don’t really understand how your answer works, and also worry that I didn’t explain my issue clearly.

I made an excerpt of my survey with the fields in question (I could send or attach it, but don't know how to do that in this thread).  Basically, the “Count Before” and “Count After” fields are readonly and contain the value 0, and the Yes/No radio defaults to No.

When “Yes” is selected, the two Count fields become active and can receive input.  However, if the user then selects the “No” again, the Count field becomes readonly again, but retains the previously entered value.  It needs to reset to 0 whenever the value is “No”.

Is there some way to do this?  

0 Kudos
MichelleHawks1
New Contributor II

Sorry - the image examples disappeared.  Here are two, the first of the initial state upon survey startup, and the second after the "Yes" button was selected, the Count field activated, and then the "No" button selected.

Initial Survey startup

Survey after Radio Button back to No

0 Kudos
DougBrowning
MVP Esteemed Contributor

I get what you are saying but as far as I know you cannot do it that way.  There is no way to say calc or leave it alone.  You can try if(set to no, 0, "") but as you will see it will sometimes leave it and sometimes wipe it.

The trick I use is to have 3 fields.  But with using a Grid here it gets a little tougher.  Instead use 2 fields that flip on or off.

Attached is a sample. 

Someone may have another idea.  Hope it helps.

MichelleHawks1
New Contributor II

This works wonderfully!  Thank you so much!

0 Kudos