Survey123: How to pre-calculate values for a field when the relevant question equals to false?

686
2
Jump to solution
03-26-2020 05:43 AM
Cyprus_Forest_Department
New Contributor III

Hi all. I am currently facing an issue where I want a question to remain hidden from the user, and to be revealed upon an answer. 

However, I want this field to be populated with a certain value when it is not appeared to the user.

It seams like the "default" option works for me if no relevant expression is set.

I have three fields:

  • Mixed_Hab (mixed habitat) that can be populated from a list of Yes,No
  • Perc_Primary (percentage of the primary habitat) that can be populated from a list 50,60,70,80,90
  • Perc_Secondary (percentage of the secondary habitat) that is calculated as 100-Perc_Primary.

I want to achieve the following automation for the user's input.

If Mixed_Hab = no, then:

  • Hide Perc_Primary in the form
  • Populate Perc_Primary with the value 100
  • Populate Perc_Secondary with the value 0

If Mixed_Hab = yes, then:

  • Reveal Perc_Primary in the form
  • Populate the Perc_Primary field with the value 50, and have the option to change the value based on the selection list of 50, 60, 70, 80, 90
  • Populate Perc_Secondary with the value 100-Perc_Primary

I have currently achieved the following:

If Mixed_Hab = no, then:

  • Reveal Perc_Primary in the form
  • Populate Perc_Primary with the value 100
  • Perc_Secondary remains blank

If Mixed_Hab = yes, then:

  • Reveal Perc_Primary in the form
  • Populate the Perc_Primary field with the value 50, and have the option to change the value based on the selection list of 50, 60, 70, 80, 90
  • Populate Perc_Secondary with the value 50, and change it upon the input of the field Perc_Primary based on the calculation 100-Perc_Primary

I have attached the form for your convenience. Sorry for the unrecognized characters, its Greek...

Thanks in advance for the support.

0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi, 

'Relevant' does not mean that the question is hidden; it means that the question is not being asked as part of the survey (and thus it's value will be null).  You can create the workflow of having a question that is initially non-relevant and store a value by creating a 3-question set:

1) The user-response question that has a relevant condition (q1)

2) A hidden or calculate question that stores the value when the user has not provided input (q2)

3) A calculate question using the coalesce(${q1}, ${q2}) function to store q1's value when present and otherwise use q2's. (qfinal)

q1 and q2 can have the bind::esri:fieldType value set to null as we don't need to store those values, only final's value.

View solution in original post

0 Kudos
2 Replies
JamesTedrick
Esri Esteemed Contributor

Hi, 

'Relevant' does not mean that the question is hidden; it means that the question is not being asked as part of the survey (and thus it's value will be null).  You can create the workflow of having a question that is initially non-relevant and store a value by creating a 3-question set:

1) The user-response question that has a relevant condition (q1)

2) A hidden or calculate question that stores the value when the user has not provided input (q2)

3) A calculate question using the coalesce(${q1}, ${q2}) function to store q1's value when present and otherwise use q2's. (qfinal)

q1 and q2 can have the bind::esri:fieldType value set to null as we don't need to store those values, only final's value.

0 Kudos
Cyprus_Forest_Department
New Contributor III

Thank you very much, it worked!

0 Kudos