I have a point feature layer with a related table (one to many).
In this related table I have fields for Name, Amount and GUID.
What I would like is to calculate the Sum of the amounts entered and have that added to the attribute table of my feature layer.
I made a Sum field in my feature layer and with calculate in AGOL was able to do this manually using this arcade expression:
var relatedRecords = FeatureSetByRelationshipName($feature, "RelTable");
var totalAmount = 0;
for (var record in relatedRecords) {
if (!IsEmpty(record.Amount)) {
totalAmount += record.Amount;
}
}
return totalAmount;
------------------------------
However I would like this to be done automatically each time a new entry is added or removed from the related table (this will be done mostly in Field Maps).
I tried to make a python script to achieve this but so far haven't been able to get it to update the feature layer.
Can anyone help me out? I'm very new to writing code.