Select to view content in your preferred language

Can a calculation rule update a record in the same feature class, same field, as the edited record?

842
4
09-26-2023 11:49 AM
mfiegeeqt
New Contributor

For example, if a user edits the common_name for OID1, I want the attribute rule to additionally update the common_name for OID 2. Is this possible?

OIDcustom_idcommon_name
1"Group A""Name A"
2"Group A""Name A"
3"Group B""Name B"
4"Group B""Name B"
4 Replies
Bud
by
Esteemed Contributor

I've wondered about this, too.

I posted it as an idea: When a feature is edited, update a different feature in the same FC

0 Kudos
JohannesLindner
MVP Frequent Contributor

Yes, that is possible.

You just have to take precautions against infinite loops (feature 1 updates f2, which in turn updates f1, which then updates f2, etc).

// Calculation Attribute Rule on TestPoints
// field: empty
// Triggers: Update
// Exclude from application evaluation!

// get the old and new value
var old_value = $originalfeature.TextField1
var new_value = $feature.TextField1

// abort if value did not change
if(new_value == old_value) { return }

// get all features with the old value that aren't the current feature
var gid = $feature.GlobalID
var other_features = Filter(FeaturesetByName($datastore, "TestPoints"), "TextField1 = @old_value AND GlobalID <> @gid")

// create and fill an update array
var updates = []
for(var f in other_features) {
    Push(updates, {globalID: f.GlobalID, attributes: {TextField1: new_value}})
}

// instruct ArcGIS to update the other features
return {
    edit: [{
        className: "TestPoints",
        updates: updates
    }]
}

 

Before:

JohannesLindner_0-1695823870649.png

 

JohannesLindner_1-1695823897924.png

 

 

After refreshing the table:

JohannesLindner_2-1695823919433.png

 


Have a great day!
Johannes
Jake_S
by Esri Contributor
Esri Contributor

Any thoughts on this issue? Calculation works and does not work depending on number of features.

Seems this user is using your code and is running into an issue. I can replicate this issue.

JS_Esri_0-1697544784320.png

@Aнастасия88 

~Jake

0 Kudos
Aнастасия88
Regular Contributor

Hi Jake, appreciate for your follow up regarding the problem that I have come across.

I still have not been able to figure out what the cause is. Hope someone will find a solution.

0 Kudos