<?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 Fetch Attribute From Nearby Feature on Field Maps in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/fetch-attribute-from-nearby-feature-on-field-maps/m-p/1200937#M4264</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have been trying to do the fetch attributes from nearby features arcade code that I have seen on blog, github and various other community posts by @Anonymous User&amp;nbsp;. I cannot get it to work for my field map.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// If feature doesn't have geometry return null
if (IsEmpty(Geometry($feature))) { return null }

// Get the parcels layer
var parcels = FeatureSetById($map, /* Yurok Addresses */ "17d69e9a280-layer-9")

// Buffer the current location and intersect with parcels
var bufferedLocation = Buffer($feature, 3000, 'feet')
var candidateParcels = Intersects(parcels, bufferedLocation)

// Calculate the distance between the parcel and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateParcels) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, "feet"),
            'feature': f
        }
    )
}

// Sort the candidate parcels by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)

// Get the closest feature
var closestFeatureWithDistance = First(sorted)

// If there was no feature, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }

// Return the address
return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I get the error "failed to calculate" every time. We are surveying for water tank placements and trying to make it easier on our fieldworkers. If all else fails, I will have them write it in or create a domain but would prefer to have it auto populate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should I change "ADDNUM" and "ADDRESSNAM" to something within my layer? Attached is a list of field names for my Address layer. I could just use "Full Address" or "Label" instead of "Address_number" and "StreetName"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read on one post that it could be because of the spatial reference but that was supposed to be fixed in the last release and I am not getting that same error message. I am still fairly new at Arcade but was able to implement a code for the child table auto population from this parent layer. If I can get this next one to work correctly, it would be incredibly useful in other projects.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Aug 2022 17:48:21 GMT</pubDate>
    <dc:creator>KatiePiper</dc:creator>
    <dc:date>2022-08-09T17:48:21Z</dc:date>
    <item>
      <title>Fetch Attribute From Nearby Feature on Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/fetch-attribute-from-nearby-feature-on-field-maps/m-p/1200937#M4264</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have been trying to do the fetch attributes from nearby features arcade code that I have seen on blog, github and various other community posts by @Anonymous User&amp;nbsp;. I cannot get it to work for my field map.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// If feature doesn't have geometry return null
if (IsEmpty(Geometry($feature))) { return null }

// Get the parcels layer
var parcels = FeatureSetById($map, /* Yurok Addresses */ "17d69e9a280-layer-9")

// Buffer the current location and intersect with parcels
var bufferedLocation = Buffer($feature, 3000, 'feet')
var candidateParcels = Intersects(parcels, bufferedLocation)

// Calculate the distance between the parcel and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateParcels) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, "feet"),
            'feature': f
        }
    )
}

// Sort the candidate parcels by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)

// Get the closest feature
var closestFeatureWithDistance = First(sorted)

// If there was no feature, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }

// Return the address
return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I get the error "failed to calculate" every time. We are surveying for water tank placements and trying to make it easier on our fieldworkers. If all else fails, I will have them write it in or create a domain but would prefer to have it auto populate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should I change "ADDNUM" and "ADDRESSNAM" to something within my layer? Attached is a list of field names for my Address layer. I could just use "Full Address" or "Label" instead of "Address_number" and "StreetName"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read on one post that it could be because of the spatial reference but that was supposed to be fixed in the last release and I am not getting that same error message. I am still fairly new at Arcade but was able to implement a code for the child table auto population from this parent layer. If I can get this next one to work correctly, it would be incredibly useful in other projects.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 17:48:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/fetch-attribute-from-nearby-feature-on-field-maps/m-p/1200937#M4264</guid>
      <dc:creator>KatiePiper</dc:creator>
      <dc:date>2022-08-09T17:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch Attribute From Nearby Feature on Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/fetch-attribute-from-nearby-feature-on-field-maps/m-p/1210042#M4432</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;You just need to change this line of the code&lt;/P&gt;&lt;LI-CODE lang="python"&gt;return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`&lt;/LI-CODE&gt;&lt;P&gt;To this&lt;/P&gt;&lt;LI-CODE lang="python"&gt;return `${closestFeatureWithDistance['feature']['Address_number']} ${closestFeatureWithDistance['feature']['StreetName']}`&lt;/LI-CODE&gt;&lt;P&gt;also you need to paly with buffer number to get result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:55:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/fetch-attribute-from-nearby-feature-on-field-maps/m-p/1210042#M4432</guid>
      <dc:creator>anonymous55</dc:creator>
      <dc:date>2022-09-06T18:55:25Z</dc:date>
    </item>
  </channel>
</rss>

