Select to view content in your preferred language

Pull date from previous record in a child table

115
3
a week ago
Labels (2)
AustinPhelps1
New Contributor

I am trying to calculate a field in field maps using the arcade expression.

I have a parent/child relationship and I need to pull the last recording date to populate a field on the new record created.

 

Here is what I have, and it is currently not working. What am I missing in my expression?

//Fetch the related inspections from the related table using the relationship name
var inspections = FeatureSetByRelationshipName($feature, "Corrosometer_Probe_Data_Records", ["Read_Date"], false);

 

//Sort inspections by the read date in descending order to get the most recent
var sortedInspections = OrderBy(inspections, "Read_Date DESC");

 

//Get the first (latest) inspection date
var latestInspection = First(sortedInspections);

 

//If there are previous inspections, get the date of the latest inspection
if (!IsEmpty(latestInspection)) {
  return latestInspection["Read_Date"];
} else {
  //If no previous inspections exist, return null or a default value
  return null;
}
 
 
Thanks for any help!
0 Kudos
3 Replies
Amanda__Huber
MVP Regular Contributor

Hi @AustinPhelps1 , 

This sounds very similar to on of our current projects which uses relationship classes (1:Many) with related table information being pulled into our parent table's popup. 

Here is example for what we did to pull the top 3 records and diplay in a popup. I believe you could just pull the top one record instead. 

Amanda__Huber_0-1728338637841.png

I believe you might need the "Top()" function for your script for it to work. https://developers.arcgis.com/arcade/function-reference/featureset_functions/#top

Amanda__Huber_1-1728338752389.png

Hope this helps! 

Best, 

Amanda Huber

0 Kudos
AustinPhelps1
New Contributor

Doesn't seem to have worked, but thank you for the suggestion. I keep getting this when running it: Test execution error: Execution error - Invalid parameter. Verify test data.

AustinPhelps1_0-1728392795672.png

I have 1500 records in my child table and 28 points in the parent so I know there is data in them

0 Kudos
Amanda__Huber
MVP Regular Contributor

Try adding this as well, this matches up the parent's GlobalID with the related table's GUID so it knows what parent record to pull from. 

Amanda__Huber_0-1728393376343.png

Best of luck, 

Amanda Huber

0 Kudos