<?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 Code for find and return values? in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183663#M6446</link>
    <description>&lt;P&gt;More details about what you're doing would help. If you're using this for a popup, then it's running on a per-feature basis, and using a big FeatureSet function like this doesn't really make sense.&lt;/P&gt;&lt;P&gt;What feature is this originating from? What fields does it have?&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2022 17:22:32 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-06-16T17:22:32Z</dc:date>
    <item>
      <title>Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183514#M6438</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need arcade code to return borough name for each community boards. My table don't have borough name field and I can't add one. I have only community board code. Each community board start with specific number which represent each borough.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this code so far&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var portal = Portal("https://www.arcgis.com")
var CD = FeatureSetByPortalItem(Portal,
"itemID",0,['BoroCD'], true);

if (Find("1",['BoroCD'], 0)&amp;gt;0) {
   return "Manhattan";
} else if (Find("2", ['BoroCD'], 0)&amp;gt;0) {
   return "Bronx";
} else if(Find("3", ['BoroCD'], 0)&amp;gt;0) {
   return "Brooklyn";
} else if(Find("4", ['BoroCD'], 0)&amp;gt;0) {
   return "Queens";
} else if(Find("5", ['BoroCD'], 0)&amp;gt;0) {
   return "Staten Island"
}

return CD&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 19:00:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183514#M6438</guid>
      <dc:creator>anonymous55</dc:creator>
      <dc:date>2022-06-16T19:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183532#M6439</link>
      <description>&lt;P&gt;Are all codes three digit numbers? If so, you could do something like this &amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var feature = $feature.BoroCD;

var boro = when (feature &amp;lt; 200, "Manhattan",
      feature &amp;lt; 300, "Bronx",
      feature &amp;lt; 400, "Brooklyn",
      feature &amp;lt; 500, "Queens",
      feature &amp;lt; 600, "Staten Island",
      "Other");

var board = Number(Mid(feature, 1,3));      
return Concatenate([boro, board], " ");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 14:19:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183532#M6439</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-06-16T14:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183560#M6440</link>
      <description>&lt;P&gt;Thanks for replay&amp;nbsp;&lt;BR /&gt;I don't have $feature,BoroCD.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 19:02:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183560#M6440</guid>
      <dc:creator>anonymous55</dc:creator>
      <dc:date>2022-06-16T19:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183567#M6441</link>
      <description>&lt;P&gt;What you're getting from FeatureSetByPortalItem is a &lt;A href="https://developers.arcgis.com/arcade/guide/types/#featureset" target="_self"&gt;FeatureSet&lt;/A&gt;, or a collection of features. You will have to cycle through them using a &lt;A href="https://developers.arcgis.com/arcade/guide/logic/#for-loops" target="_self"&gt;For loop&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal("https://www.arcgis.com")
var CD = FeatureSetByPortalItem(Portal,
"ea60eba0707d40a1be2f43696e2cca9f",0,['BoroCD'], true);

for (var feature in CD) {
  //code
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 16 Jun 2022 15:00:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183567#M6441</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-06-16T15:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183638#M6442</link>
      <description>&lt;P&gt;Can you confirm what kind of field&amp;nbsp;&lt;STRONG&gt;BoroCD&lt;/STRONG&gt; is?&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp;provided a really good solution with the&amp;nbsp;&lt;STRONG&gt;When&amp;nbsp;&lt;/STRONG&gt;function. Perhaps you could convert the field to a number first, then put it through that?&lt;/P&gt;&lt;P&gt;Alternate approach: &lt;STRONG&gt;Distinct&lt;/STRONG&gt;. It's not really what the function is meant for, but it allows us to use SQL to generate the new field, and is usually a lot faster than a for loop, especially for something simple like this.&lt;/P&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal("https://www.arcgis.com")

var fs = FeatureSetByPortalItem(
    portal,
    "ea60eba0707d40a1be2f43696e2cca9f",
    0,
    ['BoroCD'],
    false // unless you *really* need the geometry, setting this to 'true' usually impacts performance more than it's worth
);

var sql = `CASE
WHEN BoroCD LIKE '2%' THEN 'Manhattan'
WHEN BoroCD LIKE '3%' THEN 'Bronx'
WHEN BoroCD LIKE '4%' THEN 'Brooklyn'
WHEN BoroCD LIKE '5%' THEN 'Queens'
WHEN BoroCD LIKE '6%' THEN 'Staten Island'
ELSE 'Other'
END`

return Distinct(
    fs,
    [
        {name: 'objectid', expression: 'objectid'},
        {name: 'BoroCD', expression: 'BoroCD'},
        {name: 'borough_name', expression: sql}
    ]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I tested this with a fake FeatureSet, and got these results:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1655397945245.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43647i7CD86276594C6F00/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1655397945245.png" alt="jcarlson_0-1655397945245.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 16:46:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183638#M6442</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-06-16T16:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183646#M6443</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;This is working but how can I get return in popup I am getting&amp;nbsp;&lt;STRONG&gt;[object Object]&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 17:01:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183646#M6443</guid>
      <dc:creator>anonymous55</dc:creator>
      <dc:date>2022-06-16T17:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183663#M6446</link>
      <description>&lt;P&gt;More details about what you're doing would help. If you're using this for a popup, then it's running on a per-feature basis, and using a big FeatureSet function like this doesn't really make sense.&lt;/P&gt;&lt;P&gt;What feature is this originating from? What fields does it have?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 17:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183663#M6446</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-06-16T17:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code for find and return values?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183672#M6449</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal("https://www.arcgis.com")
var CD = FeatureSetByPortalItem(Portal,
"ea60eba0707d40a1be2f43696e2cca9f",0,['BoroCD'], true);
var CD1 = First(Intersects($feature, CD));
var CDCode = CD1.BoroCD
var boro = when (CDCode &amp;lt; 200, "Manhattan",
      CDCode &amp;lt; 300, "Bronx",
      CDCode &amp;lt; 400, "Brooklyn",
      CDCode &amp;lt; 500, "Queens", "Staten Island");

var board = Mid(CDCode, 1, 3);      
return Concatenate([boro, board], " ");&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 16 Jun 2022 17:40:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code-for-find-and-return-values/m-p/1183672#M6449</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-06-16T17:40:18Z</dc:date>
    </item>
  </channel>
</rss>

