Select to view content in your preferred language

Arcade code to find values in the middle of a string and return a value in ArcGIS Dashboards.

1679
3
Jump to solution
06-24-2021 12:03 PM
kdaw_gis
Occasional Contributor

I have a survey from Survey123 with a field that allows users to select multiple answers. This data is stored in the feature class in the format option1,option2,option4. 

I would like this to display in the dashboard in the format Option1, Option2, Option4. 

I tried using the find function (see below) however it only finds the first selection in the list. In the below example there it would not find option2 and return the "" string. 

iif(Find("option2",$datapoint["example_field_name"])==0,"Option 2","")

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Haven't worked with Arcade in Dashboards yet, but in other applications it would work like this:

 

var options = Split($datapoint["example_field_name"], ",")
var formatted_options = []

var formats = [
  ["option1", "Option 1"],
  ["option2", "Option 2"],
  ["option3", "blah"],
  ["option4", "blub"]
]

for(var f in formats) {
  if(Includes(options, formats[f][0])) {
    Push(formatted_options, formats[f][1])
  }
}

return Concatenate(formatted_options, ", ")

 


Have a great day!
Johannes

View solution in original post

3 Replies
Waffle_House
Frequent Contributor

Can you explain more? Where are you trying to put the Arcade? In a data expression, formatting expression or somewhere else?

Have you tried calculating a new field and displaying that?

Screenshots always recommended.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Haven't worked with Arcade in Dashboards yet, but in other applications it would work like this:

 

var options = Split($datapoint["example_field_name"], ",")
var formatted_options = []

var formats = [
  ["option1", "Option 1"],
  ["option2", "Option 2"],
  ["option3", "blah"],
  ["option4", "blub"]
]

for(var f in formats) {
  if(Includes(options, formats[f][0])) {
    Push(formatted_options, formats[f][1])
  }
}

return Concatenate(formatted_options, ", ")

 


Have a great day!
Johannes
kdaw_gis
Occasional Contributor

This worked beautifully.  Thank you for your help!

0 Kudos