<?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 Expressions and Related Records count not working if no related record exists in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328245#M54565</link>
    <description>&lt;P&gt;I have been forced into using arcade expressions to HTML format data as part of this I have to use some related records.&amp;nbsp; The relationship between the feature class and the related table is one to many or none as such some of the features do not have a related record.&lt;/P&gt;&lt;P&gt;for debugging purpose I have taken the relationship part out into into a separate expression what I have at moment is this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var x=FeatureSetByRelationshipName($feature, "drainageIAforms_1",['FluvfloodRisk'],false)
Console(x)
console(IsEmpty(x))
console(Count(x))
console(first(x))
var result=''
if (Count(x)&amp;gt;0) {
  var y=first(x)
  result = y.FluvfloodRisk
  }
  else {
    result= 'No Data'
  }


return { 
	type : 'text', 
	text : result
}&lt;/LI-CODE&gt;&lt;P&gt;works perfectly if there is a related record there, I get the expected return and the console populates as you would expect and it takes a reasonable amount of time to return.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_0-1694609862984.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80593iA81266A0C42AEC00/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_0-1694609862984.png" alt="LarryMcEvoy70_0-1694609862984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When no related record exists its a totally different issue. the output flags an error and the console output stops at the count.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_1-1694610496871.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80594i97C0031E787C69D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_1-1694610496871.png" alt="LarryMcEvoy70_1-1694610496871.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_2-1694610545377.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80595i5AD324E4768EC78E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_2-1694610545377.png" alt="LarryMcEvoy70_2-1694610545377.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Even more confusing is the popup populates but is slow&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_3-1694611134205.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80596iCBBA00A77F8E7373/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_3-1694611134205.png" alt="LarryMcEvoy70_3-1694611134205.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought the count of the feature set was the way to check if there were records is there something I am missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance if anyone has a solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2023 13:21:02 GMT</pubDate>
    <dc:creator>LarryMcEvoy70</dc:creator>
    <dc:date>2023-09-13T13:21:02Z</dc:date>
    <item>
      <title>Arcade Expressions and Related Records count not working if no related record exists</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328245#M54565</link>
      <description>&lt;P&gt;I have been forced into using arcade expressions to HTML format data as part of this I have to use some related records.&amp;nbsp; The relationship between the feature class and the related table is one to many or none as such some of the features do not have a related record.&lt;/P&gt;&lt;P&gt;for debugging purpose I have taken the relationship part out into into a separate expression what I have at moment is this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var x=FeatureSetByRelationshipName($feature, "drainageIAforms_1",['FluvfloodRisk'],false)
Console(x)
console(IsEmpty(x))
console(Count(x))
console(first(x))
var result=''
if (Count(x)&amp;gt;0) {
  var y=first(x)
  result = y.FluvfloodRisk
  }
  else {
    result= 'No Data'
  }


return { 
	type : 'text', 
	text : result
}&lt;/LI-CODE&gt;&lt;P&gt;works perfectly if there is a related record there, I get the expected return and the console populates as you would expect and it takes a reasonable amount of time to return.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_0-1694609862984.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80593iA81266A0C42AEC00/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_0-1694609862984.png" alt="LarryMcEvoy70_0-1694609862984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When no related record exists its a totally different issue. the output flags an error and the console output stops at the count.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_1-1694610496871.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80594i97C0031E787C69D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_1-1694610496871.png" alt="LarryMcEvoy70_1-1694610496871.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_2-1694610545377.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80595i5AD324E4768EC78E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_2-1694610545377.png" alt="LarryMcEvoy70_2-1694610545377.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Even more confusing is the popup populates but is slow&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LarryMcEvoy70_3-1694611134205.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80596iCBBA00A77F8E7373/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LarryMcEvoy70_3-1694611134205.png" alt="LarryMcEvoy70_3-1694611134205.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought the count of the feature set was the way to check if there were records is there something I am missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance if anyone has a solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:21:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328245#M54565</guid>
      <dc:creator>LarryMcEvoy70</dc:creator>
      <dc:date>2023-09-13T13:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expressions and Related Records count not working if no related record exists</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328255#M54567</link>
      <description>&lt;P&gt;This one had me stumped a couple of weeks ago. As you pointed out the related record you are testing against has no match. Since it can't find a match, even though it looks like an empty feature set is returned it's more like a null and it can't perform that function on a null value. I think what I would do is instead of using Count(x) &amp;gt; 0 use !IsEmpty(x).&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:41:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328255#M54567</guid>
      <dc:creator>LanceKirby2</dc:creator>
      <dc:date>2023-09-13T13:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expressions and Related Records count not working if no related record exists</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328262#M54568</link>
      <description>&lt;P&gt;I used a similar methodology on a popup and don't experience a lag or problems in the console&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS", ['FILENETLINK', 'DOCGUID'], false);
var relatedCount = count(related);
var output;

if (relatedCount == 0) {
  output = `&amp;lt;p&amp;gt;There are no surveys for this property.&amp;lt;\p&amp;gt;`;
} else if (relatedCount == 1) {
  var rec = First(related);
  output = `There is 1 survey for this property:
    &amp;lt;br&amp;gt;&amp;amp;nbsp •  &amp;lt;a href="${rec.FILENETLINK}"&amp;gt;${rec.DOCGUID}&amp;lt;/a&amp;gt;`;
} else {
  output = `There are ${relatedCount} surveys for this property:`;
  for (var rec in related) {
    output += `&amp;lt;br&amp;gt;&amp;amp;nbsp •  &amp;lt;a href="${rec.FILENETLINK}"&amp;gt;${rec.DOCGUID}&amp;lt;/a&amp;gt;`;
  }
}

return { 
	type : 'text', 
	text : output
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="console.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80597iFEAD44549C292988/image-size/medium?v=v2&amp;amp;px=400" role="button" title="console.png" alt="console.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:56:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328262#M54568</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-09-13T13:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expressions and Related Records count not working if no related record exists</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328398#M54580</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/developers-questions/arcade-error-when-accessing-empty-feature-set/m-p/196403#M1200" target="_blank" rel="noopener"&gt;Solved: Re: Arcade error when accessing empty feature set - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Just in case anyone comes across this the problem was already solved in the link above, I had not notice that I had nulls within my foreign key once I implemented a check for it job was golden thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp;if you had not shown me it working I would have just left it as the result was coming in.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 17:20:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expressions-and-related-records-count-not/m-p/1328398#M54580</guid>
      <dc:creator>LarryMcEvoy70</dc:creator>
      <dc:date>2023-09-13T17:20:23Z</dc:date>
    </item>
  </channel>
</rss>

