<?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 Arcade script not working (Portal) in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525417#M61024</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an arcade script that I often use to return the closest value to a given point. In this case, an address number. When I try it in this particular instance, I receive "&lt;SPAN&gt;Test execution error: Execution error - Cannot access value using a key of this type. Verify test data."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is my script. The funny thing is that I copied it from another calculation (in field maps) just to return an ID from a water main. I am not sure why this one isn't working.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;address&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;$map&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"Addresses"&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;searchDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Intersects&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;address&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;Buffer&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;searchDistance&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'miles'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;minDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Infinity&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;for&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;place&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt;){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;placeDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Distance&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;place&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'mile'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;placeDistance&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt; &lt;/SPAN&gt;&lt;SPAN&gt;minDistance&lt;/SPAN&gt;&lt;SPAN&gt;){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;minDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;placeDistance&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;place&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;bldg_num&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;thank you!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 21 Aug 2024 20:28:23 GMT</pubDate>
    <dc:creator>leahmaps</dc:creator>
    <dc:date>2024-08-21T20:28:23Z</dc:date>
    <item>
      <title>Arcade script not working (Portal)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525417#M61024</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an arcade script that I often use to return the closest value to a given point. In this case, an address number. When I try it in this particular instance, I receive "&lt;SPAN&gt;Test execution error: Execution error - Cannot access value using a key of this type. Verify test data."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is my script. The funny thing is that I copied it from another calculation (in field maps) just to return an ID from a water main. I am not sure why this one isn't working.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;address&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;$map&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"Addresses"&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;searchDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Intersects&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;address&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;Buffer&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;searchDistance&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'miles'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;minDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Infinity&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;for&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;place&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt;){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;placeDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Distance&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;place&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'mile'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;placeDistance&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt; &lt;/SPAN&gt;&lt;SPAN&gt;minDistance&lt;/SPAN&gt;&lt;SPAN&gt;){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;minDistance&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;placeDistance&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;place&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;closestPlace&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;bldg_num&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;thank you!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 21 Aug 2024 20:28:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525417#M61024</guid>
      <dc:creator>leahmaps</dc:creator>
      <dc:date>2024-08-21T20:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade script not working (Portal)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525471#M61030</link>
      <description>&lt;P&gt;Try running one line at a time, or use Console to check output, to see where the error occurs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 22:01:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525471#M61030</guid>
      <dc:creator>ZenMasterZeke</dc:creator>
      <dc:date>2024-08-21T22:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade script not working (Portal)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525520#M61037</link>
      <description>&lt;P&gt;Where are you running this? Depending on the context, &lt;STRONG&gt;$map &lt;/STRONG&gt;may not be available.&lt;/P&gt;&lt;P&gt;The function &lt;STRONG&gt;Intersects&lt;/STRONG&gt; returns a FeatureSet. Your expression replaces &lt;EM&gt;closestPlace&lt;/EM&gt; with &lt;EM&gt;place&lt;/EM&gt; if there's a feature found within the buffer, but if there isn't then closestPlace will still be a FeatureSet.&lt;/P&gt;&lt;P&gt;Personally, I would avoid re-using a variable for different types of objects. You might try something like this. By creating a placeholder place with a null value, and by keeping the FeatureSet and the Feature in their own variables, we don't get issues when we try to call the value at the end.&lt;/P&gt;&lt;P&gt;And yes, a dictionary and Feature are different types of objects, I know, but in this case, you can call their attributes in the same way.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var address = FeatureSetByName($map, "Addresses")
var searchDistance = 1
var closePlaces = Intersects(address, Buffer($feature, searchDistance, 'miles'))
var minDistance = Infinity

// create placeholder closest place with a building number
var closestPlace = {'bldg_num':null}

for (var place in closePlaces){
  var placeDistance = Distance(place, $feature, 'mile');
  if (placeDistance &amp;lt; minDistance){
    minDistance = placeDistance;
    closestPlace = place;
  }
};

return closestPlace['bldg_num']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 23:36:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525520#M61037</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-08-21T23:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade script not working (Portal)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525631#M61045</link>
      <description>&lt;P&gt;Have you checked the following?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;That the "bldg_num" field exists in the feature layer you are querying. If not, then you would get a key error as that name would not exist in the attributes dictionary. To check for this you can do a check using HasKey before accessing that attribute.&lt;/LI&gt;&lt;LI&gt;That closestPlace is not null when you are trying to access it's attribute, which would be the case if the nearest feature was more than the search distance away.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can also use Console statements to check variable values, which should appear in the browser developer console.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 08:52:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525631#M61045</guid>
      <dc:creator>JohnFannon</dc:creator>
      <dc:date>2024-08-22T08:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade script not working (Portal)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525680#M61047</link>
      <description>&lt;P&gt;Hi Josh,&lt;/P&gt;&lt;P&gt;This is running in the calculate section where you set up arcade for field maps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only reason I am stumped as to why this one doesn't work, is because I am using the exact same expression (just different layers) in another field maps field and it works just fine.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="leahmaps_0-1724329732289.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/113233iDF268BDAED06068A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="leahmaps_0-1724329732289.png" alt="leahmaps_0-1724329732289.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I will give what you have a shot and see if that works instead.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 12:29:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525680#M61047</guid>
      <dc:creator>leahmaps</dc:creator>
      <dc:date>2024-08-22T12:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade script not working (Portal)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525682#M61048</link>
      <description>&lt;P&gt;Yep, I checked both of these. bldg_num is in the layer (directly added from the variables tab). and I don't think closest place should ever be null, but it may be possible. There are also no null features in the feature layer.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 12:34:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-script-not-working-portal/m-p/1525682#M61048</guid>
      <dc:creator>leahmaps</dc:creator>
      <dc:date>2024-08-22T12:34:29Z</dc:date>
    </item>
  </channel>
</rss>

