<?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 Help completing Arcade Script in AGOL to extract &amp;amp; sum lengths from a layer and insert into another layer based on matching fields in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602025#M64249</link>
    <description>&lt;P&gt;Hello, I'm trying to write a script in Field Maps that will extract and Sum the values from a field in one layer and then insert that value into a field in another layer based on matching fields.&amp;nbsp; I found some example of code that I think is what I need, or at least close to what I need but I can't figure out how to tailor it to my needs.&amp;nbsp; I have a basic understanding of Arcade and have been stuck on this for days.&lt;/P&gt;&lt;P&gt;I have several Project Areas with Cables running throughout the various areas.&amp;nbsp; My goal is to have a script that will Sum the total Length of cables in each project area, and then insert that total into a field in the Project Area, and it does this based on the Area ID in the Cable layer Matching the Area ID in the Project Areas layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a script that can do this based on Cables that intersect the Project Area, but that won't work because numerous Cables intersect multiple Project Areas, but they are only assigned a single Area ID and thus I want that footage to be attributed to the total for that single Area.&lt;/P&gt;&lt;P&gt;I've included what I have so far below.&amp;nbsp; When I run the script in the code creation box, the output message gives me the Length total for the Entire Cable layer, and then when I go back to the map and click on a Design Area polygon the field is just blank, it doesn't give any footage.&amp;nbsp; Appreciate any help you could offer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var Cables = FeatureSetByName($map, "Cable", ['Area_ID', 'Length'], true)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var Areas = FeatureSetByName($map, "Project Areas", ['Area_ID'], true)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var totalsum = 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for (var $feature in Areas) {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; var matchvalue = $feature["Area_ID"]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var relatedfeatures = Filter(Cables, "Area_ID = @matchvalue")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for (var $feature in relatedfeatures) {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; totalsum += $feature["Length"]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; }&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;return totalSum&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Apr 2025 20:38:25 GMT</pubDate>
    <dc:creator>Mowgli_GIS</dc:creator>
    <dc:date>2025-04-02T20:38:25Z</dc:date>
    <item>
      <title>Help completing Arcade Script in AGOL to extract &amp; sum lengths from a layer and insert into another layer based on matching fields</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602025#M64249</link>
      <description>&lt;P&gt;Hello, I'm trying to write a script in Field Maps that will extract and Sum the values from a field in one layer and then insert that value into a field in another layer based on matching fields.&amp;nbsp; I found some example of code that I think is what I need, or at least close to what I need but I can't figure out how to tailor it to my needs.&amp;nbsp; I have a basic understanding of Arcade and have been stuck on this for days.&lt;/P&gt;&lt;P&gt;I have several Project Areas with Cables running throughout the various areas.&amp;nbsp; My goal is to have a script that will Sum the total Length of cables in each project area, and then insert that total into a field in the Project Area, and it does this based on the Area ID in the Cable layer Matching the Area ID in the Project Areas layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a script that can do this based on Cables that intersect the Project Area, but that won't work because numerous Cables intersect multiple Project Areas, but they are only assigned a single Area ID and thus I want that footage to be attributed to the total for that single Area.&lt;/P&gt;&lt;P&gt;I've included what I have so far below.&amp;nbsp; When I run the script in the code creation box, the output message gives me the Length total for the Entire Cable layer, and then when I go back to the map and click on a Design Area polygon the field is just blank, it doesn't give any footage.&amp;nbsp; Appreciate any help you could offer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var Cables = FeatureSetByName($map, "Cable", ['Area_ID', 'Length'], true)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var Areas = FeatureSetByName($map, "Project Areas", ['Area_ID'], true)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var totalsum = 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for (var $feature in Areas) {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; var matchvalue = $feature["Area_ID"]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var relatedfeatures = Filter(Cables, "Area_ID = @matchvalue")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for (var $feature in relatedfeatures) {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; totalsum += $feature["Length"]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; }&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;return totalSum&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 20:38:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602025#M64249</guid>
      <dc:creator>Mowgli_GIS</dc:creator>
      <dc:date>2025-04-02T20:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help completing Arcade Script in AGOL to extract &amp; sum lengths from a layer and insert into another layer based on matching fields</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602036#M64250</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/662145"&gt;@Mowgli_GIS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're definitely on the right track, I looked through and made some changes for you that should get you in the right spot:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var Cables = FeatureSetByName($map, "Cable", ['Area_ID', 'Length'], true)
var Areas = FeatureSetByName($map, "Project Areas", ['Area_ID'], true)

var currentAreaID = $feature["Area_ID"]

var relatedCables = Filter(Cables, "Area_ID = @currentAreaID")

var totalSum = 0

for (var cable in relatedCables) {
    totalSum += cable["Length"]
}

return totalSum&lt;/LI-CODE&gt;&lt;P&gt;In this, you should be placing this into the Project Area layers field calculator so it'll run for each of the featutes. The Area_ID will get the area ID as long as that matches the field names, and we filter the Cables layer down to the cables that match the Area_ID, then finally we sum the cables with the matching Area_ID instead of all.&lt;/P&gt;&lt;P&gt;Let me know if this works out for you!&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 20:51:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602036#M64250</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-04-02T20:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Help completing Arcade Script in AGOL to extract &amp; sum lengths from a layer and insert into another layer based on matching fields</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602322#M64261</link>
      <description>&lt;P&gt;Thanks Cody!! This worked great!&amp;nbsp; Appreciate the help and feedback!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 13:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-completing-arcade-script-in-agol-to-extract/m-p/1602322#M64261</guid>
      <dc:creator>Mowgli_GIS</dc:creator>
      <dc:date>2025-04-03T13:56:32Z</dc:date>
    </item>
  </channel>
</rss>

