An Attribute rule script that updates the same table, works with any number of rows.
//if the common_name hasn't change quit.
if ($feature.common_name == $originalfeature.common_name) return;
//if this field has this value set, it means attribute rules has set it. We can use it to stop execution so we don't do further updates.
//We want to reset the original value of the field.
//This field can be any existing field or a new field.
if ($feature.t == 1 && $originalFeature.t != 1 ) return {"result": {"attributes": {"t": $originalFeature.t}}}
//grab the variables
var g = $feature.group_name
var gid = $feature.GlobalID
var n = $feature.common_name
//look up all common_names same group and update them, we want to avoid updating the same feature and features with same name.
var fs = Filter($featureset, "group_name = @g and globalid <> @gid and (common_name <> @n or common_name is null)")
var updates = []
for (var f in fs)
push (updates, {"globalId": f.globalid, "attributes": {"common_name": n , "t": 1}}) //set the field to 1 indicating attribute rules did the update.
return {
"edit": [{"className": "main.mytable", "updates": updates}]
}
Article Discussion: