1

I have an ArcGIS geodatabase with a parent feature class related to a child stand alone table containing the various inspections made on each parent feature. Primary key is GlobalID and foreign key is GUID.

In ArcGIS Pro, I'm trying to edit an attribute rule to automatically populate a LAST_DATE_INSPECTION field in the parent feature class with the most recent inspection (DATE_INSPECTION field in the child table).

The code I did is only updating the parent LAST_DATE_INSPECTION field with the first inserted inspection date of the child table, not the most recent date. Looks like my filter isn't working. enter image description here

The actual code:

// calculation attribute rule on child table, field DATE_INSPECTION
// triggers: Insert, Update, Delete

//Foreign key in child table
var fk = $feature.GUID

//Load all inspections of the feature//
var related_inspection = FeatureSetByName($datastore, "CHILD_TABLE_NAME",['GUID'],false)

//Filter the most recent inspection date of the feature
var last_inspection = First(Filter(related_inspection, 'GUID = @fk'))

//Return nothing if no date found
if(IsEmpty(last_inspection)){
return ;
}

//Updating DATE_INSPECTION field in parent feature class
return {
"result": fk,
     "edit": [{
        "className" : "PARENT_FC_NAME",
           "updates": [{
             //selecting the parent feature to update
             "GlobalID" : last_inspection.GUID,
             //Update the DATE_INSPECTION field in parent feature class 
             "attributes" : {'DATE_INSPECTION': last_inspection.DATE_INSPECTION
}
                       }]
              }]    
};

1 Answer 1

0

I was missing one step : ordering the filtered features

//Foreign key in child table
var fk = $feature.GUID
   
//Load all inspections of the feature 
var inspections = FeatureSetByName($datastore, "CHILD_TABLE_NAME",['GUID'],false) 
var related_inspections = Filter(inspections, 'GUID = @fk')


//(MISSING STEP WITH OrderBy)Filter the most recent inspection date of the set
var last_inspection = First(OrderBy(related_inspections, "DATE_INSPECTION
DESC"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.