Field contains multiple values separated by comma, want to list each on own line in popup.

197
3
Jump to solution
a month ago
AriLukas
Occasional Contributor

Hello all, 

 

I have a Survey123 form that has a question that allows multiple answers. When the survey is submitted the field (Hazards) where the answers are input shows each value, separated by a comma (see screenshot below). For example some of the possible answers are Roof_Open, Holes_in_floor, Hazardous_Material. 

I would like the popup to display each of the answers on a new line so instead of being a list separated by commas, as shown above, it would appears as:        Hazards: Roof_Open

                                                                                                            Holes_in_floor

                                                                                     

AriLukas_0-1713812056229.png

I have tried creating an Array and then concatenating with the TexFormatting.NewLine but have not had any luck. 

Any insight would be greatly appreciated!

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Building on @SteveCole , once you have an array of items, use the function Concatenate to turn the array into a single string. This avoids having an extra line break at the end.

return Concatenate(
  Split($feature['hazards'], ','),
  '\n'
)

Then again, if your items are broken up by commas, you could just use Replace.

return Replace($feature['hazards'], ',', '\n')

You could also use Replace to swap the underscores for spaces.

var spaced = Replace($feature['hazards'], '_', ' ')

return Replace(spaced, ',', '\n')
- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
SteveCole
Frequent Contributor

Easy to do with Arcade. Instead of showing your Hazards field in the popup, you would should an Arcade expression instead:

var theList = Split("dog,chair,pony,table,sunshine,rainbow",',');
var theOutput;

for(var index in theList) {
  theOutput = theOutput + theList[index] + '\n';
};
return Trim(theOutput);

 

In my code sample, you would change out my comma delineated text string with a reference to whatever field in your data that has that list (e.g. $feature.Hazards).

jcarlson
MVP Esteemed Contributor

Building on @SteveCole , once you have an array of items, use the function Concatenate to turn the array into a single string. This avoids having an extra line break at the end.

return Concatenate(
  Split($feature['hazards'], ','),
  '\n'
)

Then again, if your items are broken up by commas, you could just use Replace.

return Replace($feature['hazards'], ',', '\n')

You could also use Replace to swap the underscores for spaces.

var spaced = Replace($feature['hazards'], '_', ' ')

return Replace(spaced, ',', '\n')
- Josh Carlson
Kendall County GIS
AriLukas
Occasional Contributor

Thank you @jcarlson  and @SteveCole  for both of your replies. I had to slightly tweak the above code but I got it to work. I probably should have mentioned I am working in Classic viewer, the below code is what I got to work. 

var spacedHazards = Replace($feature.hazards, '_', ' ')

return Replace(spacedHazards, ',', '\n')

Thank you both again!