<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcade expressions adding comma to multiple expressions in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298243#M52744</link>
    <description>&lt;P&gt;So, the issue seems to be that nested &lt;STRONG&gt;for k in...&lt;/STRONG&gt; loop. It's going through and replacing &lt;EM&gt;strings&lt;/EM&gt;, and I imagine, in ascending order. So it's looking for "4", for example, and it will recognize a match in 24, 34, 47, etc., since the actual string exists.&lt;/P&gt;&lt;P&gt;Two ways to get around this come to mind.&lt;/P&gt;&lt;P&gt;Option 1: Reverse sort your basin names so that single-digit values are replaced &lt;EM&gt;last&lt;/EM&gt;, ensuring that they only trigger on values not caught be two-digit values.&lt;/P&gt;&lt;P&gt;Option 2: Use the basin values as&amp;nbsp;&lt;STRONG&gt;keys&lt;/STRONG&gt;. Remember that&amp;nbsp;&lt;STRONG&gt;dict['key']&amp;nbsp;&lt;/STRONG&gt;returns the value in that key.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var splits = Split($feature.Subbasin, ',')

for(var a in splits){
  splits[a] = basinNames[splits[a]]
}&lt;/LI-CODE&gt;&lt;P&gt;See how that does.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jun 2023 18:33:13 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2023-06-12T18:33:13Z</dc:date>
    <item>
      <title>Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1074935#M41031</link>
      <description>&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have rows of data with abbreviations of Bachelor programs that I want to fully describe in the pop-up. Therefore I made this arcade expression for each bachelor program:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var txt = Split($feature.Opleiding, '/')
if (IndexOF(txt, 'BA') &amp;gt; -1) {
    return 'Bedrijfskunde en agribusiness'
}&lt;/LI-CODE&gt;&lt;P&gt;Sometimes a row has multiple bachelor programs active (i.e. BA/TA). In the Pop-Up all expressions are active, see screenshot. If the program is not in the dataset, it will not be shown.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2021-07-01 221550.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/17555i6C5F9537408C3F94/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2021-07-01 221550.png" alt="Screenshot 2021-07-01 221550.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This way, both studies will show up, but without a comma or 'and'. So that is why I added this expression (expression/expr0)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (Find('/', $feature.Opleiding, 0) &amp;gt; -1) {
    return ', '
}&lt;/LI-CODE&gt;&lt;P&gt;However three combinations or more from these studies are also possible. Now I randomly put down the expression somewhere in the pop-up. As you might have guessed the comma sometimes will be placed before the bachelor programs or after...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The question:&lt;/STRONG&gt; How could I solve this problem so the comma will be placed in between the corresponding active expressions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 20:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1074935#M41031</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-01T20:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1074948#M41032</link>
      <description>&lt;P&gt;The answer is probably "you can't", at least, not without rewriting some of your expressions, or adding a new expression on top of them.&lt;/P&gt;&lt;P&gt;For your popup to adjust based on what your expressions are returning would be its own expression, and can be handled very nicely with the &lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#concatenate" target="_self"&gt;&lt;STRONG&gt;Concatenate&lt;/STRONG&gt;&lt;/A&gt; function. Really, though, there's no reason for those expressions to all be separate. Consider the following code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var rep_dict = {
    'BA': 'Bedrijfskunde en agribusiness',
    'SE': 'Something Else',
    'AT': 'Another Thing'
    // and so on
}

var prog_arr = Split($feature.Opleiding, '/')

for(var a in prog_arr){
  for(var k in rep_dict){
        prog_arr[a] = Replace(prog_arr[a], k, rep_dict[k])
    }
}

return Concatenate(prog_arr, ', ')&lt;/LI-CODE&gt;&lt;P&gt;Running this on a test value of 'SE/AT/BA' returns&lt;/P&gt;&lt;PRE&gt; Something Else, Another Thing, Bedrijfskunde en agribusiness&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 20:48:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1074948#M41032</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-07-01T20:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1074951#M41034</link>
      <description>&lt;P&gt;Hi Josh Carlson,&lt;/P&gt;&lt;P&gt;Of course thanks. I wasn't sure you could make dictionaries in Arcade and this is obviously way cleaner. Thank you very much for the quick reply!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 20:56:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1074951#M41034</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-01T20:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1297677#M52705</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;-&lt;/P&gt;&lt;P&gt;I know this is a few years old, but hoping you might be able to assist. I came across this solution and it looked like it would fit the bill for my problem, however I am experiencing a strange output and am baffled.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem&lt;/STRONG&gt;: I have a hosted feature layer that is managed via Survey123. One of the select_multiple questions stores codes for each selected subbasin. These codes are not helpful in a pop-up, so I wanted to use Arcade to replace the code with the subbasin name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not getting an error, but the returned values are incorrect when I compare the stored subbasin codes with the reported subbasin names in the pop-up.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var basinNames = {
    '1': 'Asnebumskit (Mill St)',
    '2': 'Asnebumskit (Princeton)',
    '3': 'Asnebumskit Pond',
    '4': 'Babcock Brook',
}
// and so on - this is a sample of code list, which contains 212 values

var splits = Split($feature.Subbasin, ',')

for(var a in splits){
  for(var k in basinNames){
        splits[a] = Replace(splits[a], k, basinNames[k])
    }
}

return Concatenate(splits, ', ')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, one record has stored values in the Subbasin attribute field of: 23,40,44,65. These codes correspond with:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="erica_poisson_0-1686330678689.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/72794i5EBD320D789B61EC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="erica_poisson_0-1686330678689.png" alt="erica_poisson_0-1686330678689.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But instead, my returned value in the pop-up is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="erica_poisson_2-1686330774395.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/72796iD27D94540D542B28/image-size/medium?v=v2&amp;amp;px=400" role="button" title="erica_poisson_2-1686330774395.png" alt="erica_poisson_2-1686330774395.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even in a situation where only one subbasin was selected the returned subbasin from the Arcade script is incorrect. In this example, there was only one subbasin selected so the name (from domain label) shows up for "Subbasin(s)" in bottom row (65 = this option) and you can see the incorrect name returned in the first row:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="erica_poisson_3-1686330922197.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/72798i285C1E24E583C0FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="erica_poisson_3-1686330922197.png" alt="erica_poisson_3-1686330922197.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Do you have any suggestions? I will keep working on this, but if you see something please let me know!&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:16:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1297677#M52705</guid>
      <dc:creator>erica_poisson</dc:creator>
      <dc:date>2023-06-09T17:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298014#M52718</link>
      <description>&lt;P&gt;Strange! I looks like it's somehow evaluating &lt;EM&gt;per digit&lt;/EM&gt;? Notice how in your longer example, you get "Babcock BrookBabcock Brook" when the value should be "44". I'm guessing 4 = "Babcock Brook" in your domain? Following that line of thought, I would guess that "Ball Brook" = 5?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 13:03:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298014#M52718</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-06-12T13:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298202#M52739</link>
      <description>&lt;P&gt;Ah yes! That is exactly what's happening. My select_multiple field is a string w/ length of 2. This was an exercise in bringing to region's data together - one region used numeric codes 1 to 90 and the other used two-letter abbreviations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I look at an example that has comma separated two-letter abbreviations, the code appears to work properly. The correct subbasin names are returned and there are no odd duplicates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to get around this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 17:29:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298202#M52739</guid>
      <dc:creator>erica_poisson</dc:creator>
      <dc:date>2023-06-12T17:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298243#M52744</link>
      <description>&lt;P&gt;So, the issue seems to be that nested &lt;STRONG&gt;for k in...&lt;/STRONG&gt; loop. It's going through and replacing &lt;EM&gt;strings&lt;/EM&gt;, and I imagine, in ascending order. So it's looking for "4", for example, and it will recognize a match in 24, 34, 47, etc., since the actual string exists.&lt;/P&gt;&lt;P&gt;Two ways to get around this come to mind.&lt;/P&gt;&lt;P&gt;Option 1: Reverse sort your basin names so that single-digit values are replaced &lt;EM&gt;last&lt;/EM&gt;, ensuring that they only trigger on values not caught be two-digit values.&lt;/P&gt;&lt;P&gt;Option 2: Use the basin values as&amp;nbsp;&lt;STRONG&gt;keys&lt;/STRONG&gt;. Remember that&amp;nbsp;&lt;STRONG&gt;dict['key']&amp;nbsp;&lt;/STRONG&gt;returns the value in that key.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var splits = Split($feature.Subbasin, ',')

for(var a in splits){
  splits[a] = basinNames[splits[a]]
}&lt;/LI-CODE&gt;&lt;P&gt;See how that does.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 18:33:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298243#M52744</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-06-12T18:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expressions adding comma to multiple expressions</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298751#M52781</link>
      <description>&lt;P&gt;Hi Josh -&amp;nbsp;&lt;/P&gt;&lt;P&gt;That modified code snippet worked perfectly and now is returning the proper values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 18:47:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-adding-comma-to-multiple/m-p/1298751#M52781</guid>
      <dc:creator>erica_poisson</dc:creator>
      <dc:date>2023-06-13T18:47:37Z</dc:date>
    </item>
  </channel>
</rss>

