Accessing the transaction change set in a modification callback
In the onSave Callback method, Structr provides access to the added, modified and removed property values of a node. The following Server-side JavaScript example illustrates the concept:
{
var mods = Structr.retrieve('modifications');
if (mods.before.name === null && mods.after.name !== null) {
Structr.log('Name was modified.');
}
}
Example
The modifications
object of changing the name of an object to “test” is this:
{
before: {
name: null
},
after: {
name: "test"
}
}
Example 2
The modifications
object of adding a Milestone to a Project:
{
before: {
milestones: null
},
after: {
milestones: [
]
},
added: {
milestones: [
"fadc950151a94f4185d66a4a42f76258"
]
},
removed: {
}
}
Please note that for relationship properties, the before
and after
collections only contain the name of the modified property, whereas the added
and removed
collections contain the actual changes. Please also note that only the UUID of the related object is stored in the collection.