<?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 a related record only if it passes filter in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352555#M37742</link>
    <description>&lt;P&gt;I thought that might be the issue too, but updating the expression to this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var asset_id = $feature.GlobalID
var relatedTable = FeatureSetByName($map, "Tree Inventory Form",['Maintenance_Performed','Date','TreeInv_Rel']);
var sortedTable = OrderBy(relatedTable, 'Date DESC')
var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = "Removal"');
var relatedRecord = First(Filter(onlyRemoved, "TreeInv_Rel = @asset_id"))

console ("Related Record:",relatedRecord)

var recordDate = relatedRecord.Date
var maintPerformed = relatedRecord.Maintenance_Performed
console ("Record Date: ",recordDate,TextFormatting.NewLine,"Maintenance performed: ",maintPerformed)

if(relatedRecord == null) { 
  return 
  }

else if (!isEmpty(recordDate) &amp;amp;&amp;amp; maintPerformed == 'Removal'){
  return Text(recordDate,'MMM DD, YYYY')
  }

else if(isEmpty(recordDate) &amp;amp;&amp;amp; maintPerformed == 'Removal'){
  return ' an unrecorded date'
  }

else {
  return
}&lt;/LI-CODE&gt;&lt;P&gt;gives me the error with no indication of where it's coming from (though presumably the new filter statement somehow):&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Expected "'", "(", "+", "-", "@", "CASE", "DATE", "EXTRACT", "FALSE", "INTERVAL", "N'", "NULL", "POSITION", "SUBSTRING", "TIMESTAMP", "TRIM", "TRUE", "`", [ \t\n\r], [0-9], or [A-Za-z_\x80-&amp;#65535;] but "\"" found.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2023 15:18:16 GMT</pubDate>
    <dc:creator>ZachBodenner</dc:creator>
    <dc:date>2023-11-22T15:18:16Z</dc:date>
    <item>
      <title>Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352535#M37740</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a set of data (Trees) with a related table (Maintenance Performed on Trees), both added to a web map. The related table contains records of tree removals, chemical treatments, inspections, etc.&amp;nbsp; I want to set up an Arcade expression to get related records only if they satisfy the criteria of "Maintenance_Performed" = "Removal". The easy solution would be to set a filter on the table in the web map structure, but the users need all of the records for purposes beyond just this expression. However, the table can contain multiple related records, and my expression is currently having trouble returning only removal records:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var asset_id = $feature.GlobalID
var relatedTable = FeatureSetByName($map, "Tree Inventory Form",['Maintenance_Performed','Date','TreeInv_Rel']);
var sortedTable = OrderBy(relatedTable, 'Date DESC')
//var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = Removal')
var relatedRecord = First(Filter(sortedTable, "TreeInv_Rel = @asset_id"))

console ("Related Record:",relatedRecord)

var recordDate = relatedRecord.Date
var maintPerformed = relatedRecord.Maintenance_Performed
console ("Record Date: ",recordDate,TextFormatting.NewLine,"Maintenance performed: ",maintPerformed)

if(relatedRecord == null) { 
  return 
  }

else if (!isEmpty(recordDate) &amp;amp;&amp;amp; maintPerformed == 'Removal'){
  return Text(recordDate,'MMM DD, YYYY')
  }

else if(isEmpty(recordDate) &amp;amp;&amp;amp; maintPerformed == 'Removal'){
  return ' an unrecorded date'
  }

else {
  return
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried this a couple ways: the way that the expression is shown above is trying to set the return based on Maintenance_Performed as a variable. I think this doesn't work though because the filter isn't necessarily accessing the right record. For example, I have a tree with two records: record one on 12/15/2021 is Removal, and record 2 on 7/28/2022 is a stump removal. If I access the most recent record, the filter pulls the stump grind record even though I want the removal record.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My next thought was to try another filter so that only "Maintenance_Performed = Removal" passes the filter. That's the "&lt;SPAN&gt;//var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = Removal')" line, but when I uncomment that out and change the next variable to use onlyRemoved, I get the error "Unknown Error."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I'm close, can anyone get me over the hump?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 14:36:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352535#M37740</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-11-22T14:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352552#M37741</link>
      <description>&lt;P&gt;You need to put quotes around Removal in your filter&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = "Removal"');&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Nov 2023 15:08:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352552#M37741</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-11-22T15:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352555#M37742</link>
      <description>&lt;P&gt;I thought that might be the issue too, but updating the expression to this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var asset_id = $feature.GlobalID
var relatedTable = FeatureSetByName($map, "Tree Inventory Form",['Maintenance_Performed','Date','TreeInv_Rel']);
var sortedTable = OrderBy(relatedTable, 'Date DESC')
var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = "Removal"');
var relatedRecord = First(Filter(onlyRemoved, "TreeInv_Rel = @asset_id"))

console ("Related Record:",relatedRecord)

var recordDate = relatedRecord.Date
var maintPerformed = relatedRecord.Maintenance_Performed
console ("Record Date: ",recordDate,TextFormatting.NewLine,"Maintenance performed: ",maintPerformed)

if(relatedRecord == null) { 
  return 
  }

else if (!isEmpty(recordDate) &amp;amp;&amp;amp; maintPerformed == 'Removal'){
  return Text(recordDate,'MMM DD, YYYY')
  }

else if(isEmpty(recordDate) &amp;amp;&amp;amp; maintPerformed == 'Removal'){
  return ' an unrecorded date'
  }

else {
  return
}&lt;/LI-CODE&gt;&lt;P&gt;gives me the error with no indication of where it's coming from (though presumably the new filter statement somehow):&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Expected "'", "(", "+", "-", "@", "CASE", "DATE", "EXTRACT", "FALSE", "INTERVAL", "N'", "NULL", "POSITION", "SUBSTRING", "TIMESTAMP", "TRIM", "TRUE", "`", [ \t\n\r], [0-9], or [A-Za-z_\x80-&amp;#65535;] but "\"" found.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 15:18:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352555#M37742</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-11-22T15:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352578#M37743</link>
      <description>&lt;P&gt;Is it possible that the Maintenance_Performed field uses a domain?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 15:36:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352578#M37743</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-11-22T15:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352586#M37744</link>
      <description>&lt;P&gt;Oh yeah it does for sure! Where would be the place to add Domain() to the expression? When I try to add it to the filter statement like Filter(Domain(... the expression builder doesn't like it.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 15:42:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352586#M37744</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-11-22T15:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352605#M37745</link>
      <description>&lt;LI-CODE lang="javascript"&gt;var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = 1'); //or whatever the domain code is for Removal&lt;/LI-CODE&gt;&lt;P&gt;You should use the numeric domain code, since the SQL function won't understand how to work with them.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 16:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352605#M37745</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-11-22T16:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352615#M37746</link>
      <description>&lt;P&gt;I'm very sorry, I'm not entirely sure I understand. So if the domain is a text string only coded domain, there's no way to use the attribute in a filter? If that's the case, is there an alternative way where I can ensure that only removal records get returned in the expression?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 16:10:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352615#M37746</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-11-22T16:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352635#M37747</link>
      <description>&lt;P&gt;What does your domain look like?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 16:28:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352635#M37747</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-11-22T16:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352645#M37748</link>
      <description>&lt;P&gt;Pretty straightforward I think. This is a referenced feature service, so the domain is stored in the egdb:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZachBodenner_0-1700671012218.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/86887i7F99900498228656/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZachBodenner_0-1700671012218.png" alt="ZachBodenner_0-1700671012218.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 16:37:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352645#M37748</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-11-22T16:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352661#M37749</link>
      <description>&lt;P&gt;That SQL statement is picky! Try this instead (changing the quotes)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var onlyRemoved = Filter(sortedTable,"Maintenance_Performed = 'Removal'");&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Nov 2023 16:59:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352661#M37749</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-11-22T16:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - return a related record only if it passes filter</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352683#M37750</link>
      <description>&lt;P&gt;That's so finnicky, especially since everywhere else Arcade is quote-type-agnostic. Thanks for the help as always Ken, you're a pro!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2023 17:36:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-return-a-related-record-only-if-it-passes/m-p/1352683#M37750</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-11-22T17:36:05Z</dc:date>
    </item>
  </channel>
</rss>

