<?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 expression help: updating parent features from related inspection table in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536519#M1571</link>
    <description>&lt;P&gt;I believe you have to get it from the $datastore, like you got the parent table.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Sep 2024 17:38:47 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2024-09-09T17:38:47Z</dc:date>
    <item>
      <title>Arcade expression help: updating parent features from related inspection table</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536449#M1568</link>
      <description>&lt;P&gt;I am trying to create an attribute rule on a related inspection table that will update a field in the parent table when new inspection records are created (or existing ones are updated). I would like to calculate the most recent inspection date (to fill in the parent table's 'last_monitored' field).&lt;/P&gt;&lt;P&gt;The code that I currently have says that it's valid in the arcade expression builder but comes up with an error when I try to create an inspection record in a Pro web map. The error is in line 18 (var ordered_dates) and states that there is an "expected feature set". Any ideas on what to edit to make this code work as intended? Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// filter the parent class for only related features

var features = $feature
var parent_id = $feature.GUID;
var parent_class = FeatureSetByName($datastore, "FFS_GIS.ArchSite_Pl", ["GlobalID", "Last_Monitored"], false);
var parent_match = Filter(parent_class, "GlobalID = @parent_id");

// count records and return null if no entries have been made

var cnt = Count(parent_match);

if (cnt == 0) {
return null
}; 

// order inspection records by most recent to oldest entries and retain most recent record

var ordered_dates = OrderBy($feature, "Monitor_Date DESC");
var relatedinfo = "";
if (cnt &amp;gt; 0) {
var info = First(ordered_dates);
relatedinfo = info.Monitor_Date;


// update parent table field with most recent record data

return {
"result" : $feature.field,
"edit": [
{
"className" : "FFS_GIS.ArchSite_Pl",
"adds": [
{
"attributes":
{
"Last_Monitored" : relatedinfo
}
}
]
}
]
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 14:56:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536449#M1568</guid>
      <dc:creator>KarynaB</dc:creator>
      <dc:date>2024-09-09T14:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression help: updating parent features from related inspection table</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536485#M1569</link>
      <description>&lt;P&gt;You're supplying a Feature to the OrderBy function, which needs a FeatureSet. Are you trying to order the FeatureSet that the feature is a part of or the parent layer?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 16:11:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536485#M1569</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-09-09T16:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression help: updating parent features from related inspection table</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536498#M1570</link>
      <description>&lt;P&gt;I am trying to order the FeatureSet that the feature is a part of (the inspection table), what command should I use instead of $feature?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 16:36:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536498#M1570</guid>
      <dc:creator>KarynaB</dc:creator>
      <dc:date>2024-09-09T16:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression help: updating parent features from related inspection table</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536519#M1571</link>
      <description>&lt;P&gt;I believe you have to get it from the $datastore, like you got the parent table.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 17:38:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536519#M1571</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-09-09T17:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression help: updating parent features from related inspection table</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536597#M1572</link>
      <description>&lt;P&gt;I was able to fix it! Here is the completed code in case anyone coming across this thread would like to reference it:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// filter the parent class for only related features
		
var parent_id = $feature.GUID;
var parent_class = FeatureSetByName($datastore, "FFS_GIS.ArchSite_Pl", ["GlobalID", "Last_Monitored"], false);
var parent_match = Filter(parent_class, "GlobalID = @parent_id");
		
// count records and return null if no entries have been made
		
var cnt = Count(parent_match);
		
if (cnt == 0) {
return null
}; 
		
// order inspection records by most recent to oldest entries and retain most recent record
		
var tabledata = FeatureSetByName($datastore, "FFS_GIS.ArchSitePl_Insp_Tb");
var ordered_dates = OrderBy(tabledata, "Monitor_Date DESC");
var relatedinfo = "";
if (cnt &amp;gt; 0) {
var info = First(ordered_dates);
relatedinfo = info.Monitor_Date;
		
		
// update parent table field with most recent record data
		
return {
"result" : $feature.GUID,
"edit": [
{
"className" : "FFS_GIS.ArchSite_Pl",
"updates": [
{"globalID" : parent_id, 
"attributes":
{
"Last_Monitored" : relatedinfo
}
}
]
}
]
}
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 09 Sep 2024 19:49:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-expression-help-updating-parent-features/m-p/1536597#M1572</guid>
      <dc:creator>KarynaB</dc:creator>
      <dc:date>2024-09-09T19:49:22Z</dc:date>
    </item>
  </channel>
</rss>

