Select to view content in your preferred language

Populate the Parent Feature with the value in a field of the child table

334
1
01-26-2024 12:25 PM
ChristineTombleson1
Occasional Contributor

I went through many of the posts that deal with populating a parent feature with a value from related child table but still can't get mine to work.

I have a BankErosionPoints Feature Layer. I have a related child inspection table named BankErosionPtInspection. A user create a point when they find an erosion area along a shoreline. During various monitoring events they observe the eroded area to determine if it is still eroding or if is stable.  The user then updates the Status field of the child table with Eroding or Stable. I want that value to be passed to the parent Erosion Point field StatusParent so that the erosion point status is kept updates as to the status of the erosion based on the inspections in the child table. My parent feature and child inspection table are related by GlobalId and BankERoPtInsp_GUID fields.  

I have placed this calculated expression in the StatusParent field in the Smart form for the BankErosionPoints parent feature layer.  However, my StatusParent field in the parent layer is never updated.  Does anyone know what I am doing wrong?  Thank you!!!

var AllReads = FeatureSetByName($map, "BankErosionPtInspection");
var ParentGlobalID = $feature.GlobalID;

var sql = "BankEroPtInsp_GUID = '" + ParentGlobalID + "'";
var RelatedReads = Filter(AllReads, sql);
var numrelreads = Count(RelatedReads);

if (numrelreads == 0) {
    return Null;
} else if (numrelreads != 0) {
    // Find the most recent related record
    var LastRelRead = First(OrderBy(RelatedReads, "CurrentReadDate DESC"));

    // Get the Status from the most recent related record
    var statusFromChild = LastRelRead.Status;

    // Update the parent feature's StatusParent field with the value from the child record
    return statusFromChild;
}

 

  

    

0 Kudos
1 Reply
ChristopherCounsell
MVP Regular Contributor

are you editing the parent feature directly and saving it?

A calculation on the parent won't trigger from an edit (add) on the child. It will only apply when the parent layer is edited and saved.

0 Kudos