<?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 - return field from related layer in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1168206#M45754</link>
    <description>&lt;P&gt;The filter query is OK. But you are right, the problem is related to the filter query and yes, something is null somewhere.&lt;/P&gt;&lt;P&gt;This is probably caused by null values in $feature.GUID.&lt;/P&gt;&lt;P&gt;When you execute this expression for a feature whose GUID is not in RelatedTable.GlobalID (but not null), Filter() returns an empty feature set, which is the reason for the empty check before accessing the First() element (better way in the code below).&lt;/P&gt;&lt;P&gt;When you execute the expression for a feature whose GUID is null, Filter() returns null and the expression fails on anything using that result, e.g. Count() or First().&lt;/P&gt;&lt;P&gt;So you just need another check at the top of the expression:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ref_guid= $feature.GUID

if(ref_guid == null) {
    // there can be no related features
    return null
}

var wells_fs=FeatureSetByName($map,"Wellsites2")
var wells_filter = Filter(wells_fs, "GlobalID = @ref_guid")
var well = First(wells_filter)

if(well == null) {
    // wells_filter is empty, no related features found
    return null
}
return well.name&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 27 Apr 2022 06:12:17 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-04-27T06:12:17Z</dc:date>
    <item>
      <title>Arcade - return field from related layer</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107114#M42547</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I need help with Arcade expression. I have polygon layer and related tables that are related based on these fields: (Global_ID=ReferenceID)&lt;/P&gt;&lt;P&gt;In the attribute table for the related table, I'd like to return a field value from related polygon layer&lt;/P&gt;&lt;P&gt;Thank you in advance!!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:35:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107114#M42547</guid>
      <dc:creator>LylianAvero</dc:creator>
      <dc:date>2021-10-13T15:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return field from related layer</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107125#M42549</link>
      <description>&lt;LI-CODE lang="javascript"&gt;// load your polygon featureset
// https://developers.arcgis.com/arcade/function-reference/data_functions/#featuresetbyname
var polygon_fs = FeatureSetByName(...)

// filter your polygons
var ref_id = $feature.ReferenceID
var polygon_filter = Filter(polygon_fs, "Global_ID = @ref_id")

// return the attribute
if(Count(polygon_filter) &amp;gt; 0) {
  return First(polygon_filter).Attribute
}
return null&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:47:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107125#M42549</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-10-13T15:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return field from related layer</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107133#M42552</link>
      <description>&lt;P&gt;Is the relate 1:1 or 1:M? The expression may be more or less complex depending on that. Also, what is the context in which you're using this? Certain profiles (symbology, etc) have limitations on what functions are available to you.&lt;/P&gt;&lt;P&gt;Take a look at the expression &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#featuresetbyrelationshipname" target="_blank"&gt;FeatureSetByRelationshipName&lt;/A&gt;. This will return all related features, and individual features and attributes can be accessed directly through the resulting FeatureSet.&lt;/P&gt;&lt;P&gt;In the Expression Builder, you can see related records at the bottom of the &lt;STRONG&gt;$feature&lt;/STRONG&gt; globals:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1634140281663.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25096i2D59874454BE458A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1634140281663.png" alt="jcarlson_0-1634140281663.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;From there, you can select the particular relation (if there are multiple) that you'd like to bring into your expression.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_1-1634140559095.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25097iE5144BD040702F74/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_1-1634140559095.png" alt="jcarlson_1-1634140559095.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:55:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107133#M42552</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-10-13T15:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return field from related layer</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107135#M42553</link>
      <description>&lt;P&gt;Thank you so much, it worked! I was missing "Count" part&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:58:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1107135#M42553</guid>
      <dc:creator>LylianAvero</dc:creator>
      <dc:date>2021-10-13T15:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return field from related layer</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1168071#M45742</link>
      <description>&lt;P&gt;This worked for me initially, but when I returned the next day to continue populating for other fields I received an error: &lt;STRONG&gt;"&lt;SPAN class=""&gt;Execution Error:&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;Cannot read properties of null (reading 'toString')"&lt;/STRONG&gt;.&amp;nbsp; I think the issue is stemming from the filter variable -- somehow the GlobalID and GUID are not matching? Or something is null somewhere? Do you have any ideas on how best to resolve the issue? Any help would be appreciated. Below is the code I am running.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;var wells_fs=FeatureSetByName($map,"Wellsites2")&lt;BR /&gt;var ref_guid= $feature.GUID&lt;BR /&gt;var wells_filter = Filter(wells_fs, "GlobalID = @ref_guid")&lt;/P&gt;&lt;P&gt;if(Count(wells_filter) &amp;gt; 0) {&lt;BR /&gt;return First(wells_filter).name&lt;BR /&gt;}&lt;BR /&gt;return null&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 19:24:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1168071#M45742</guid>
      <dc:creator>KelseySmuczynski</dc:creator>
      <dc:date>2022-04-26T19:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return field from related layer</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1168206#M45754</link>
      <description>&lt;P&gt;The filter query is OK. But you are right, the problem is related to the filter query and yes, something is null somewhere.&lt;/P&gt;&lt;P&gt;This is probably caused by null values in $feature.GUID.&lt;/P&gt;&lt;P&gt;When you execute this expression for a feature whose GUID is not in RelatedTable.GlobalID (but not null), Filter() returns an empty feature set, which is the reason for the empty check before accessing the First() element (better way in the code below).&lt;/P&gt;&lt;P&gt;When you execute the expression for a feature whose GUID is null, Filter() returns null and the expression fails on anything using that result, e.g. Count() or First().&lt;/P&gt;&lt;P&gt;So you just need another check at the top of the expression:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ref_guid= $feature.GUID

if(ref_guid == null) {
    // there can be no related features
    return null
}

var wells_fs=FeatureSetByName($map,"Wellsites2")
var wells_filter = Filter(wells_fs, "GlobalID = @ref_guid")
var well = First(wells_filter)

if(well == null) {
    // wells_filter is empty, no related features found
    return null
}
return well.name&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Apr 2022 06:12:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-return-field-from-related-layer/m-p/1168206#M45754</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-04-27T06:12:17Z</dc:date>
    </item>
  </channel>
</rss>

