Select to view content in your preferred language

Attribute Rule Updating Parent FC from Child Table Not Updating Field When Records Are Deleted

528
3
09-11-2024 12:48 PM
KarynaB
Occasional Contributor

I have created an attribute rule for an inspection table that will update a field in the parent feature class every time the table is updated. This rule is set to run on the 'insert', 'update', and 'delete' triggers. However, it only functions properly for the 'insert' and 'update' triggers. If I delete a row from the inspection table, the rule will not re-calculate the 'date' field and will instead retain the date of the recently deleted row. 

 

I had thought that this code was simple enough that it would just re-calculate the date field regardless of what edit actions are being performed and would keep that field up to date as a result. Any ideas why the delete action is not re-calculating the rule in the same way? Thank you!

 

My code:

 

// filter the parent class for only related features
        
var parent_id = $feature.GUID;
var parent_class = FeatureSetByName($datastore, "Parent_FeatureClass", ["GlobalID", "Date"], false);
var parent_match = Filter(parent_class, "GlobalID = @parent_id");
        
// return null if no matches are found
        
var cnt = Count(parent_match);
        
if (cnt == 0) {
return null
}; 
        
// else, order inspection records by most recent to oldest entries and retain most recent record
        
var tabledata = FeatureSetByName($datastore, "Inspection_Table");
var ordered_dates = OrderBy(tabledata, "Date DESC");
var relatedinfo = "";
var info = First(ordered_dates);
relatedinfo = info.Date;  
        
// update parent table field with most recent record data
        
return {
        "result" : $feature.GUID,
        "edit": [
        {
        "className" : "Parent_FeatureClass",
        "updates": [
        {"globalID" : parent_id, 
        "attributes":
        {
        "Date" : relatedinfo
        }
        }
        ]
        }
        ]
        }

 

 

0 Kudos
3 Replies
KarynaB
Occasional Contributor

I partially figured out the errors in my above code and attempted to fix them with an additional if statement that matches the original feature's guid with the parent class' global id. However, I am receiving an error when trying to update the relationship (error: Missing keyword 'objectID or globalID' in the 'updates' array or dictionary). Any ideas where I went wrong? 

 

// filter the parent class for only related features
    
var originalguid = $originalfeature.GUID
var parent_id = $feature.GUID;
var parent_class = FeatureSetByName($datastore, "Parent_FeatureClass", ["GlobalID", "Date"], false);
var parent_match = Filter(parent_class, "GlobalID = @parent_id");
                
    
// return null if no matches are found
            
if(parent_match == null)  { 
return {
    "result" : null,
    "edit": [
        {"className" : "Parent_FeatureClass",
        "updates": [
            {"globalID" : originalguid, 
            "attributes":
            {"Date" : null}
            }
        ]
        }
    ]
}
};
        
            
// else, order inspection records by most recent to oldest entries and retain most recent record
            
var tabledata = FeatureSetByName($datastore, "Inspection_Table");
var ordered_dates = OrderBy(tabledata, "Date DESC");
var info = First(ordered_dates);
var relatedinfo = info.Date;  
           
     
// update parent table field with most recent record data
    
if(parent_match != null) {
    return {
            "result" : $feature.GUID,
            "edit": [
            {"className" : "Parent_FeatureClass",
        "updates": [
            {"globalID" : parent_id, 
            "attributes":
            {"Date" : relatedinfo}
            }
            ]
            }
            ]
}
}

 

0 Kudos
BrettLessner
Frequent Contributor

Did you ever figure out how to recalculate when you delete a related record?  

0 Kudos
RavindraSingh
Frequent Contributor

I also have similar issue. 

There is an attribute rule (trigger on Insert, Update, and Delete) on the MaximoLocation table that sets the maximolocationid field to null in the ElectricDevice feature class whenever a feature in MaximoLocation is deleted. Simultaneously, a calculation rule on the ElectricDevice feature class ensures that, on insert or update, the maximolocationid field is populated using the ID from the MaximoLocation table.

However, when I delete a feature from MaximoLocation, the rule isn’t clearing the corresponding maximolocationid value in ElectricDevice as expected. Why might this be happening? 

To me it looks like, UpdateRule in ElectricDevice is again resetting the value from null to id from MaximoLocation, Can this be a reason?

 

ArcPro Version: 3.3.1

0 Kudos