Select to view content in your preferred language

Survey123 Connect - Populate a text field when only specific choices are selected from multiple questions

382
6
Jump to solution
09-23-2024 09:48 AM
DarrenLloyd__DOIT
Regular Contributor

My goal is to create an “Additional Cost” field that populates choices from various questions throughout the survey. Basically, a submitter will select question choices and only specific choices will populate in the “Additional Cost” field. I got this to work when I only reference one field in the calculation column. However, there are multiple fields I would like to bring.

The expression below works and the ArcGIS_Developer_Subscription text is placed in the “Additional Cost” field.

  • if(${ent_specialty_lic}='ArcGIS_Developer_Subscription', "ArcGIS_Developer_Subscription", " ")

However, I cannot find a way to use multiple IF statements. Here are examples of other choices I would like to bring in to the “Additional Cost” field.

  • if(${ent_additional_portal_products}='ArcGIS_Insights', "ArcGIS_Insights", " ")
  • if(${singleuse_pro_ext}='ArcGIS_Aviation_Airports_for_Pro', "ArcGIS_Aviation_Airports_for_Pro", " ")

Any help would be greatly appreciated and welcomed.

0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

That is how if statements work, once one of the statements evaluate to true, it stops. You likely want to set up multiple temporary fields to do each if statement separately and then combine them into a single field. 

2024-09-26_8-45-58.gif

 

- Jen

View solution in original post

6 Replies
JenniferAcunto
Esri Regular Contributor

You chain them so that the default answer for one is the next if statement...

if(${ent_specialty_lic}='ArcGIS_Developer_Subscription', "ArcGIS_Developer_Subscription", if(${ent_additional_portal_products}='ArcGIS_Insights', "ArcGIS_Insights", if(${singleuse_pro_ext}='ArcGIS_Aviation_Airports_for_Pro', "ArcGIS_Aviation_Airports_for_Pro", " ")))
- Jen
0 Kudos
DarrenLloyd__DOIT
Regular Contributor

Thank you for your reply. Your method works when selecting a single choice (select_single) in a question. However I have questions that are multiple choice (select_multiple) and a submitter could pick 2+ choices in the same question. I tried using the selected() function in the expression but Survey123 throws an error when updating the XLS. 

Error - Invalid calculate for the bind attached to "$additionalCost"; null in expression...

example - If(selected(${singleuse_pro_ext},'ArcGIS_Aviation_Airports_for_Pro')....
0 Kudos
JenniferAcunto
Esri Regular Contributor

It is the same basic principle. 

if(selected(${ent_specialty_lic}, 'ArcGIS_Developer_Subscription'), 'ArcGIS_Developer_Subscription', if(selected(${ent_additional_portal_products}, 'ArcGIS_Insights'), 'ArcGIS_Insights', if(selected(${singleuse_pro_ext}, 'ArcGIS_Aviation_Airports_for_Pro'), 'ArcGIS_Aviation_Airports_for_Pro', '')))

 

Your example has If capitalized, which Survey123 is not going to like. 

- Jen
0 Kudos
DarrenLloyd__DOIT
Regular Contributor

I really appreciate your effort with this issue. I successfully implemented "selected()" to the expression. However I have multi-choice responses for questions. Basically a user can select 2+ answers. When I add the additional response to the expression, only the first response is populated in the field. How can make sure multiple choices are recorded? 

Example - there are two potential responses for {singleuse_pro_ext}. One for Aviation and one for Interoperability. Only the Aviation response is populated in the field even though both were picked from the choice list. 

if(selected(${ent_specialty_lic}, 'ArcGIS_Developer_Subscription'), 'ArcGIS_Developer_Subscription',
if(selected(${ent_additional_portal_products}, 'ArcGIS_Insights'), 'ArcGIS_Insights',
if(selected(${singleuse_pro_ext}, 'ArcGIS_Aviation_Airports_for_Pro'), 'ArcGIS_Aviation_Airports_for_Pro',
if(selected(${singleuse_pro_ext}, 'ArcGIS_Data_Interoperability_for_Pro'), 'ArcGIS_Data_Interoperability_for_Pro',''))))
0 Kudos
JenniferAcunto
Esri Regular Contributor

That is how if statements work, once one of the statements evaluate to true, it stops. You likely want to set up multiple temporary fields to do each if statement separately and then combine them into a single field. 

2024-09-26_8-45-58.gif

 

- Jen
DarrenLloyd__DOIT
Regular Contributor

I got everything configured using your example. Thank you! 

0 Kudos