<?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 in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317625#M8277</link>
    <description>&lt;P&gt;To post code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1689266678674.png" style="width: 546px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75345i1DB988B7B4303219/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1689266678674.png" alt="JohannesLindner_0-1689266678674.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1689266693900.png" style="width: 469px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75346i06615A9413162052/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_1-1689266693900.png" alt="JohannesLindner_1-1689266693900.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var choicesDict = {
  'fields': [
    {'name': 'split_choices', 'type': 'esriFieldTypeString'},
    ],
  'geometryType': '',
  'features': []
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They are creating a &lt;A href="https://developers.arcgis.com/arcade/function-reference/dictionary_functions/#dictionary" target="_blank" rel="noopener"&gt;Dictionary&lt;/A&gt; that is used to return the final &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featureset" target="_blank" rel="noopener"&gt;Featureset&lt;/A&gt;. Featuresets are collections of features. They can be constructed from a Dictionary or from a JSON string (representing the dictionary).&lt;/P&gt;&lt;P&gt;A Featureset has to have the following keys:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;fields: an &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#array" target="_blank" rel="noopener"&gt;Array&lt;/A&gt; of Dictionaries describing the fields of the Featureset. These dictionaries have the following keys:&lt;UL&gt;&lt;LI&gt;name: String, the field's name&lt;/LI&gt;&lt;LI&gt;type: String, the field's type. The important types are:&lt;UL&gt;&lt;LI&gt;esriFieldTypeString&lt;/LI&gt;&lt;LI&gt;esriFieldTypeInteger&lt;/LI&gt;&lt;LI&gt;esriFieldTypeDouble&lt;/LI&gt;&lt;LI&gt;esriFieldTypeDate&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;alias (optional): String, the field's alias&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;geometryType: String, the geometry type of the contained features. Possible values are&lt;UL&gt;&lt;LI&gt;esriGeometryPoint&lt;/LI&gt;&lt;LI&gt;esriGeometryMultipoint&lt;/LI&gt;&lt;LI&gt;esriGeometryPolyline&lt;/LI&gt;&lt;LI&gt;esriGeometryPolygon&lt;/LI&gt;&lt;LI&gt;empty string (no geometry)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;features: Array of Dictionaries describing the contained features&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the snippet above, they are creating this structure. They are declaring the featureset to be a non-spatial table (geometryType = "") with one String field called split_choices. They leave the contained features empty. This is a common workflow. You create your dictionary and then fill in the features in a later step (see next snippet).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second snippet uses an old workflow, I'm going to update it here:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;for (var f in fs) {
  var split_array = Split(f["Report_road_condition"], ',')
  for(var i in split_arr){
    var new_feature = {
      'attributes': { 'split_choices': Trim(split_array[i]) }
      }
    Push(choicesDict.features, new_feature)
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Repeat the following block (until line 9) for each feature (f) in the input featureset (fs)&lt;/LI&gt;&lt;LI&gt;Take the value in the field Report_road_condition and &lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#split" target="_blank" rel="noopener"&gt;Split&lt;/A&gt; it by comma, creating an array of string values&lt;/LI&gt;&lt;LI&gt;Repeat the following block (until line &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; for each index in that array&lt;/LI&gt;&lt;LI&gt;create a dictionary describing a feature&lt;OL&gt;&lt;LI&gt;these dictionaries have the following keys&lt;OL&gt;&lt;LI&gt;attributes: dictionary of the feature's attributes { field_name: field_value }&lt;/LI&gt;&lt;LI&gt;geometry (optional): the feature's &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#geometry" target="_blank" rel="noopener"&gt;geometry&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#trim" target="_blank" rel="noopener"&gt;Trim&lt;/A&gt; the current element of the array and use the output as value for the field split_choices&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#push" target="_blank" rel="noopener"&gt;Push&lt;/A&gt; the feature we just created into the features array of the output dictionary&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in this step, they loop over each feature in the input featrueset, split a field value of that feature, and append each part to the output featureset. If the input featureset has one feature with the value "A, B, C", the output featureset will have three features with the values "A", "B", "C".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last step in these workflows is to return the Dictionary as Featureset:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return Featureset(choicesDict)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 10 Aug 2023 19:36:56 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-08-10T19:36:56Z</dc:date>
    <item>
      <title>Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317416#M8274</link>
      <description>&lt;P data-unlink="true"&gt;So I am following this blog,&amp;nbsp;&lt;FONT size="3"&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/ops-dashboard/announcements/introducing-data-expressions-in-arcgis-dashboards/" target="_self"&gt;Introducing Data Expressions in ArcGIS Dashboards&lt;/A&gt;,&amp;nbsp;&lt;/FONT&gt;&amp;nbsp;to learn Arcade for use in Dashboards.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Can someone please explain these two pieces of codes line by line?&lt;BR /&gt;&lt;BR /&gt;// Empty dictionary to capture each hazard reported as separate rows.&lt;BR /&gt;var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}],&lt;BR /&gt;'geometryType': '', 'features': []}; // Need help understanding the syntax&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var index = 0;&lt;/P&gt;&lt;P&gt;// Split comma separated hazard types and store in dictionary.&lt;BR /&gt;for (var feature in fs) {&lt;BR /&gt;var split_array = Split(feature["Report_road_condition"], ',')&lt;BR /&gt;var count_arr = Count(split_array)&lt;BR /&gt;for(var i = 0; i &amp;lt; count_arr; i++ ){&lt;BR /&gt;choicesDict.features[index++] = {&lt;BR /&gt;'attributes': { 'split_choices': Trim(split_array[i]), // Don't know what this line is doing&lt;BR /&gt;}}&lt;BR /&gt;}}&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 15:07:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317416#M8274</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2023-08-10T15:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317625#M8277</link>
      <description>&lt;P&gt;To post code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1689266678674.png" style="width: 546px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75345i1DB988B7B4303219/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1689266678674.png" alt="JohannesLindner_0-1689266678674.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1689266693900.png" style="width: 469px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75346i06615A9413162052/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_1-1689266693900.png" alt="JohannesLindner_1-1689266693900.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var choicesDict = {
  'fields': [
    {'name': 'split_choices', 'type': 'esriFieldTypeString'},
    ],
  'geometryType': '',
  'features': []
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They are creating a &lt;A href="https://developers.arcgis.com/arcade/function-reference/dictionary_functions/#dictionary" target="_blank" rel="noopener"&gt;Dictionary&lt;/A&gt; that is used to return the final &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featureset" target="_blank" rel="noopener"&gt;Featureset&lt;/A&gt;. Featuresets are collections of features. They can be constructed from a Dictionary or from a JSON string (representing the dictionary).&lt;/P&gt;&lt;P&gt;A Featureset has to have the following keys:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;fields: an &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#array" target="_blank" rel="noopener"&gt;Array&lt;/A&gt; of Dictionaries describing the fields of the Featureset. These dictionaries have the following keys:&lt;UL&gt;&lt;LI&gt;name: String, the field's name&lt;/LI&gt;&lt;LI&gt;type: String, the field's type. The important types are:&lt;UL&gt;&lt;LI&gt;esriFieldTypeString&lt;/LI&gt;&lt;LI&gt;esriFieldTypeInteger&lt;/LI&gt;&lt;LI&gt;esriFieldTypeDouble&lt;/LI&gt;&lt;LI&gt;esriFieldTypeDate&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;alias (optional): String, the field's alias&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;geometryType: String, the geometry type of the contained features. Possible values are&lt;UL&gt;&lt;LI&gt;esriGeometryPoint&lt;/LI&gt;&lt;LI&gt;esriGeometryMultipoint&lt;/LI&gt;&lt;LI&gt;esriGeometryPolyline&lt;/LI&gt;&lt;LI&gt;esriGeometryPolygon&lt;/LI&gt;&lt;LI&gt;empty string (no geometry)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;features: Array of Dictionaries describing the contained features&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the snippet above, they are creating this structure. They are declaring the featureset to be a non-spatial table (geometryType = "") with one String field called split_choices. They leave the contained features empty. This is a common workflow. You create your dictionary and then fill in the features in a later step (see next snippet).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second snippet uses an old workflow, I'm going to update it here:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;for (var f in fs) {
  var split_array = Split(f["Report_road_condition"], ',')
  for(var i in split_arr){
    var new_feature = {
      'attributes': { 'split_choices': Trim(split_array[i]) }
      }
    Push(choicesDict.features, new_feature)
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Repeat the following block (until line 9) for each feature (f) in the input featureset (fs)&lt;/LI&gt;&lt;LI&gt;Take the value in the field Report_road_condition and &lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#split" target="_blank" rel="noopener"&gt;Split&lt;/A&gt; it by comma, creating an array of string values&lt;/LI&gt;&lt;LI&gt;Repeat the following block (until line &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; for each index in that array&lt;/LI&gt;&lt;LI&gt;create a dictionary describing a feature&lt;OL&gt;&lt;LI&gt;these dictionaries have the following keys&lt;OL&gt;&lt;LI&gt;attributes: dictionary of the feature's attributes { field_name: field_value }&lt;/LI&gt;&lt;LI&gt;geometry (optional): the feature's &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#geometry" target="_blank" rel="noopener"&gt;geometry&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#trim" target="_blank" rel="noopener"&gt;Trim&lt;/A&gt; the current element of the array and use the output as value for the field split_choices&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#push" target="_blank" rel="noopener"&gt;Push&lt;/A&gt; the feature we just created into the features array of the output dictionary&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in this step, they loop over each feature in the input featrueset, split a field value of that feature, and append each part to the output featureset. If the input featureset has one feature with the value "A, B, C", the output featureset will have three features with the values "A", "B", "C".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last step in these workflows is to return the Dictionary as Featureset:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return Featureset(choicesDict)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Aug 2023 19:36:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317625#M8277</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-08-10T19:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317629#M8278</link>
      <description>&lt;P&gt;It's also worth to note that there are two ways to address a dictionary key or field value (the example uses both, which is ugly...)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;bracket notation with the dictionary key or field name as string:&lt;UL&gt;&lt;LI&gt;dict["key"]&lt;/LI&gt;&lt;LI&gt;$feature["Field"]&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;dot notation&lt;UL&gt;&lt;LI&gt;dict.key&lt;/LI&gt;&lt;LI&gt;$feature.Field&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Thu, 10 Aug 2023 19:41:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-code/m-p/1317629#M8278</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-08-10T19:41:41Z</dc:date>
    </item>
  </channel>
</rss>

