<?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: Issue with Arcade Attribute Rule Script - Not Returning Expected Values in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413580#M1390</link>
    <description>&lt;P&gt;Hi Stefan,&lt;/P&gt;&lt;P&gt;It does not appear that you are using the buffer polygon created from $feature. Try updating the Intersects calls to use the buffer.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2024 16:30:06 GMT</pubDate>
    <dc:creator>TedHoward2</dc:creator>
    <dc:date>2024-04-22T16:30:06Z</dc:date>
    <item>
      <title>Issue with Arcade Attribute Rule Script - Not Returning Expected Values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413483#M1389</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;I'm attempting to develop an Arcade Rule that, given a feature geometry, identifies the closest address feature within a specified buffer distance. The script should then update the created or updated features attributes with the closest attributes of the closest address feature. However, as so often, I'm encountering an issue with the script.&lt;/P&gt;&lt;P&gt;heres the script im using:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var featureGeometry = Geometry($feature)

if(isEmpty(featureGeometry)){
 return Null
}

var addressesLN = FeatureSetByName($datastore, 'VG_ADDRESSES_LN', ['*'], true)
var addressesPT = FeatureSetByName($datastore, 'VG_ADDRESSES_LN', ['*'], true)
var addressesAR = FeatureSetByName($datastore, 'VG_ADDRESSES_LN', ['*'], true)

var bufferSize = 20 
var bufferPolygon = Buffer(featureGeometry, bufferSize, 'meters')

var bufferIntersectingLN = Intersects(addressesLN, featureGeometry)
var bufferIntersectingPT = Intersects(addressesPT, featureGeometry)
var bufferIntersectingAR = Intersects(addressesAR, featureGeometry)

var mostInformativeAddresses = Null 

if(!isEmpty(bufferIntersectingPT)){
 mostInformativeAddresses = bufferIntersectingPT
} else if (!isEmpty(bufferIntersectingLN)){
 mostInformativeAddresses = bufferIntersectingLN
} else if (!isEmpty(bufferIntersectingAR)){
 mostInformativeAddresses = bufferIntersectingAR
} else {
 return
}

if(isEmpty(mostInformativeAddresses)){
 return
}

var closestFeature = Null
var closestDistance = 9999

for(var addressFeature in mostInformativeAddresses){
 var currentDistance = Distance(featureGeometry, Geometry(addressFeature), 'meters') 
 if (currentDistance &amp;lt; closestDistance){
 closestFeature = currentFeature
 closestDistance = currentDistance
}
}

return{
	"result":{
		"attributes":{
			"ADM_KEY_COMM": closestFeature.ADM_KEY_COMM, 
			"ADM_KEY_STREET": closestFeature.ADM_KEY_STREET, 
			"ADM_KEY_COMMPART": closestFeature.ADM_KEY_COMMPART, 
			"ADM_KEY_ADDRESS": closestFeature.ADM_KEY_ADDRESS, 
			"ADDRESS_TEXT": closestFeature.ADDRESS_TEXT
		}
	}
}
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script validates without errors, but it doesn't return any values, even though there is a valid address feature within a reasonable distance.&lt;/P&gt;&lt;P&gt;Can anybody help me find the issue here or suggest any improvements to the script?&lt;/P&gt;&lt;P&gt;Any assistance would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 13:08:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413483#M1389</guid>
      <dc:creator>StefanAngerer</dc:creator>
      <dc:date>2024-04-22T13:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Arcade Attribute Rule Script - Not Returning Expected Values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413580#M1390</link>
      <description>&lt;P&gt;Hi Stefan,&lt;/P&gt;&lt;P&gt;It does not appear that you are using the buffer polygon created from $feature. Try updating the Intersects calls to use the buffer.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 16:30:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413580#M1390</guid>
      <dc:creator>TedHoward2</dc:creator>
      <dc:date>2024-04-22T16:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Arcade Attribute Rule Script - Not Returning Expected Values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413620#M1391</link>
      <description>&lt;P&gt;All three featuresets are pointing to the same class, you want to fix that.&amp;nbsp; I revised the logic, code below.&amp;nbsp; I think you want something like this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var featureGeometry = Geometry($feature);

if (isEmpty(featureGeometry)) {
    return null;
}

var bufferSize = 20;
var bufferPolygon = Buffer(featureGeometry, bufferSize, 'meters');

function closest_item(fs) {

    var closestFeature = null;
    var closestDistance = INFINITY;

    for (var addressFeature in fs) {
        var currentDistance = Distance(featureGeometry, Geometry(addressFeature), 'meters')
        if (currentDistance &amp;lt; closestDistance) {
            closestFeature = currentFeature;
            closestDistance = currentDistance;
        }
    }
    return closestFeature
}

var addressesPT = FeatureSetByName($datastore, '&amp;lt;FILL OUT THE CORRECT CLASS&amp;gt;', ['*'], true);
var bufferIntersectingPT = Intersects(addressesPT, bufferPolygon);
var closest_feat = closest_item(bufferIntersectingPT);


if (IsEmpty(closest_feat)) {
    var addressesLN = FeatureSetByName($datastore, '&amp;lt;FILL OUT THE CORRECT CLASS&amp;gt;', ['*'], true);
    var bufferIntersectingLN = Intersects(addressesLN, featureGeometry);
    closest_feat = closest_item(bufferIntersectingLN);
}

if (IsEmpty(closest_feat)) {
    var addressesAR = FeatureSetByName($datastore, '&amp;lt;FILL OUT THE CORRECT CLASS&amp;gt;', ['*'], true);
    var bufferIntersectingAR = Intersects(addressesAR, featureGeometry);
    closest_feat = closest_item(bufferIntersectingAR);
}

if (isEmpty(closest_feat)) {
    return;
}


return {
    "result": {
        "attributes": {
            "ADM_KEY_COMM": closest_feat.ADM_KEY_COMM,
            "ADM_KEY_STREET": closest_feat.ADM_KEY_STREET,
            "ADM_KEY_COMMPART": closest_feat.ADM_KEY_COMMPART,
            "ADM_KEY_ADDRESS": closest_feat.ADM_KEY_ADDRESS,
            "ADDRESS_TEXT": closest_feat.ADDRESS_TEXT
        }
    }
};&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 22 Apr 2024 17:20:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/issue-with-arcade-attribute-rule-script-not/m-p/1413620#M1391</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-22T17:20:47Z</dc:date>
    </item>
  </channel>
</rss>

