Select to view content in your preferred language

Arcade expression for multi step replacement of codes from Survey123, in a list in Dashboards.

192
2
2 weeks ago
LindaKoch2
New Contributor

Hi Community folks,

I have an interesting problem.  I am new to Arcade, so this may be a simple fix.  I have a Survey123 feature service that has several attributes that have multiple entries.  I am working on a Dashboard to report out these results.  For example, one field has entries of CG, JR, TB, WB, and can include anywhere from one to all of them, separated by commas.  I want the Dashboard to report out the sentence of what they mean.  CG = Co-Governance, JR = Just Responsibility, TB = Targeted Benefits, and WB = Wealth Building.  Then list them with a <br> under a heading. I have used REPLACE to get the list effect with other entries

I have tried IIF, WHEN and DECODE, but these seem to just list the first true statement and only one instance of it (if it is the sole entry), and then ignore the rest.

 

Any help would be appreciated!  Thanks!

LindaKoch2_1-1719358284717.png

Results: (the CG, TB etc in the heading are what should show)

LindaKoch2_2-1719358454599.png

LindaKoch2_3-1719358508311.png

 

 

 

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

You're very close. First, split the field into an array based on those commas. Then you can apply Decode to everything in the array.

// split into an array
var ej_arr = Split($datapoint['ej_new'], ',')

// custom function to decode array items
function EJDecode(x) {
  return Decode(
    x,
    'CG', 'CO-GOVERNANCE…',
    'TG', 'TARGETED BENEFITS…',
    'WB', 'WEALTH-BUILDING…',
    'JR', 'JUST RESPONSIBILITY…',
    ''
  )
}

// apply EJDecode to array
ej_arr = Map(ej_arr, EJDecode)

// join array items together with line breaks
var spaced_ej = Concatenate(ej_arr, '<br>')
- Josh Carlson
Kendall County GIS
LindaKoch2
New Contributor

Thank you so much Josh, for taking the time to look at this.  I'm glad I was on the right track.  Your code helped me understand the step.  It still didn't quite work right, but instead of ',' it needed to be ', ' with the extra space after the comma.  Works great now!  Thanks again for your expert help!

0 Kudos