Survey123 Connect If/Else

1187
8
Jump to solution
10-21-2022 12:44 PM
RogerAsbury
Occasional Contributor

Came across an earlier question that noted there is no if/else syntax in Survey123 Connect. I'm trying to display a different map based on a dropdown menu of five or so choices. In most languages I could do this with a switch or if/else. The answer seemed to suggest chaining a bunch of if(selected(${}), selectedMap, defaultMap) statements, but that doesn't seem to work. 

Basically, visually:

 

if(selected(${mapChoice}, "A"), map=routetomapA, map=routetoDefault), if(selected(${mapChoice}, "B"), map=routetomapB, map=routetoDefault)

 

 

Just curious how I'd actually get this to work. Or if there's a simpler way to get this to work. What the above does is simply always show me the default map, which never changes despite changing the map choice drop down. 

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

Did some playing, and I don't think the body::esri:style column can take dynamic parameters. So instead, I have three different 'fake' maps that don't record any data. They get served to the user based on the mapChoice field. Whatever points they record for any of those maps are passed along to a single 'real' map to record the value. 

- Jen

View solution in original post

8 Replies
JenniferAcunto
Esri Regular Contributor

Your follow on if statements are the 'else' so you don't include the default option until the very end.

if(selected(${mapChoice}, "A"), 'map=routetomapA', if(selected(${mapChoice}, "B"), 'map=routetomapB', 'map=routetoDefault'))

 

- Jen
RogerAsbury
Occasional Contributor

That answer makes perfect sense, and I have no doubt it's right, so I suspect I've got a problem elsewhere. I've trimmed my code down to a single option, shown below in all its unedited glory, but it's still not working. I have confirmed both maps exist.

if(selected(${problem_type_ordered_by_most_co}, "Road Problem"), 'map=d89af64f3ff445fcb03e31168af74a47', 'map=2991f1ac981d4e398561528c1ec384b3')

This is in the body::esri:style column of a geopoint row. When you first get to the survey you can see the default map. But when you select Road Problem from the drop down menu referenced, the map does not change. Apologies for the goofy drop down menu name. 🙂

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
0 Kudos
JenniferAcunto
Esri Regular Contributor

I have not ever tried to change the map dynamically, but in theory what you have should work. I would try doing the calculation into a seperate field, and then referencing that calculation field into the body::esri:style column. While testing I would keep that calculation field visible to ensure it is populating correctly. Once it's working you can hide that field and set the field type to null.

- Jen
0 Kudos
RogerAsbury
Occasional Contributor

How would I do this calculation in a separate field and then reference that calculation in the proper field? Tried searching this online, but didn't really find an example.

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
0 Kudos
JenniferAcunto
Esri Regular Contributor

Did some playing, and I don't think the body::esri:style column can take dynamic parameters. So instead, I have three different 'fake' maps that don't record any data. They get served to the user based on the mapChoice field. Whatever points they record for any of those maps are passed along to a single 'real' map to record the value. 

- Jen
RogerAsbury
Occasional Contributor

When attempting this solution, I get the attached error.

123Cerror.png

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
0 Kudos
JenniferAcunto
Esri Regular Contributor

You can only have a single geography question that is recording data. All of the maps that we are pulling calculations from need to have the bind::esri:fieldType set to null.

- Jen
0 Kudos
RogerAsbury
Occasional Contributor

Awesome. As soon as I added the nulls to the proper field everything fell into place and started to work. 🙂 Thanks very much for your help!

--
Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough