Select to view content in your preferred language

Attribute Rule

456
1
08-07-2022 05:01 AM
UğurcanGül
New Contributor III

I want to print the name of whatever column has changed in the layer with the attribute rule in a new column.

Sample;

I have a layer called Stops.
This layer consists of columns a, b, c, d.
I opened a new column named "e" to show the changed column.
When the user changes column a, b, c or d, I want to print the name of that column in column e.

Can u help?

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

Something like this could do what you want (not tested):

// Calculation Attribute Rule
// field: e (Text)
// triggers: Insert, Update, Delete

// write "INSERT" or "DELETE" into e
if $editcontext.editType != "UPDATE" {
    return $editcontext.editType
}

// define the fields you want to check
var checked_fields = ["a", "b", "c", "d"]

// build an array of fields where the value changed
var changed_fields = []
var old_attributes = Dictionary(Text($originalfeature)).attributes
var new_attributes = Dictionary(Text($feature)).attributes
for(var f in checked_fields) {
    var field = checked_fields[f]
    if(old_attributes[field] != new_attributes[field]) {
        Push(changed_fields, field)
    }
}

// compare geometry
if(!Equals(Geometry($originalfeature), Geometry($feature))) {
    Push(changed_fields, "geometry")
}

// concatenate the field names into a string and write that into e
return Concatenate(changed_fields, ", ")

Have a great day!
Johannes
0 Kudos