You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

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.

Search results for "Accessing the transaction change set in a modification callback"

We could not find anything matching "Accessing the transaction change set in a modification callback" in our documentation. Please rephrase your search.

You can also ask your questions in the Structr Google Group or create a free account in the Structr Support Portal.
Click here to send feedback to the Structr team.