Select to view content in your preferred language

Attribute rule to calculate GPM field based on flow field

300
0
03-20-2024 11:52 AM
MikhaylaB
Frequent Contributor

I have the below Arcade set to update a parent fc when an entry is added to the inspection table. Now I need the trigger field to be calculated automatically when the flow field is updated. How can I update my code to include this logic? Parent field is "class", related table trigger field is "GPM", and I need to calculate GPM from the "Flow" field. 

var parent_id = $feature.hydrantOBJID ;
var parent_class = FeatureSetByName($datastore, "Fire.SDE.Hydrants", ["OBJECTID", 'class'], false);
var parent_records = Filter(parent_class, "OBJECTID = @parent_id");

var updates = [];
var i = 0;
var new_value = 'no gpm';

if ($feature.GPM >= 1500) {
new_value = "Blue - 1500 GPM or Greater";
}
else if ($feature.GPM >= 1000) {
new_value = "Green - 1000-1499 GPM";
}
else if ($feature.GPM >= 500){
new_value = "Orange - 500-999 GPM";
}
else {
new_value = "Red - 0-499 GPM";
}

 

for (var row in parent_records) {
// If the parent row is null or has a different value, updated it
if (IsEmpty(row['class']) || row['class'] != new_value)
{
updates[i++] = {
'OBJECTID': parent_id,
'attributes': {"class": new_value}
};
}
}

Tags (1)
0 Kudos
0 Replies