Easy way to get all attributes that have been updated?

noahMDMi
noahMDMi Member Posts: 8
Photogenic First Comment
**

I have a script that has multiple different sections where different attributes may be updated.

Is there a way for me to see which attributes have been marked for update (i.e. the resulting list of set_attributes for a record, so I can see what all attributes have been updated after I've processed my record? My reason for this is so that I can log the record name and any attributes that have been updated on it, and I would prefer not to keep track of the attributes throughout the updates.

I see a __attributes_to_update variable on the Record class, which does what I want, but since it's a private attribute (and gets mangled to be _Record__attributes_to_update), I was wondering if there was a better way to access it?

Best Answer

  • Andy_Grigg
    Andy_Grigg Member, Employee Posts: 27
    5 Answers 10 Comments Name Dropper First Anniversary
    ✭✭✭✭
    Answer ✓

    No, there is no documented way to see which attributes are currently staged for update in a record. If this is something you need, I'd recommend writing your code to track separately which attributes have been added/removed, maybe with a method that calls the set_attributes() method.

    For logging purposes, a pattern I've used previously is to write a custom logging handler that stores changes as they are made, but only emits the log once the changes are committed to MI.

    As for why this isn't in the public API, ultimately the way we store attributes that are staged for import isn't a fundamental part of the API, and it isn't something that we want to make public, because then it would be much more difficult to change it.