Hi,
i'm currently working on something for which i need the before and after state of a property's value (Document.Text aka name) for a rename operation.
i've looked at the Document.AfterSave/BeforeSave events but they seem to give only the currentstate.
So is there anyway to access both value states of Text in these events or in the AbstractDataEditor.DataEditorControl.onsave?
Basic idea is that you subscribe to two events: Document.BeforeSave and Document.AfterSave. First event (BeforeSave) fires with sender document version that is "old" and second event (AfterSave) fires with "new" version. Then you can use "old" version to fetch data from database and update it with "new version".
private void Document_BeforeSaveHandler(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
// save sender in class field or something, call it beforeSave.
}
private void Document_AfterSaveHandler(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
// save sender in class field, call it afterSave.
// then you can do something like
databaseHelper.Update(beforeSave, afterSave);
// and maybe set beforeSave = null; and afterSave = null;
}
That is roughly what I do and it works really well for me :)
Before/after save Document Value state
Hi, i'm currently working on something for which i need the before and after state of a property's value (Document.Text aka name) for a rename operation.
i've looked at the Document.AfterSave/BeforeSave events but they seem to give only the currentstate.
So is there anyway to access both value states of Text in these events or in the AbstractDataEditor.DataEditorControl.onsave?
thanks
HI
Yes, it is possible and I am doing it right now.
Basic idea is that you subscribe to two events: Document.BeforeSave and Document.AfterSave. First event (BeforeSave) fires with sender document version that is "old" and second event (AfterSave) fires with "new" version. Then you can use "old" version to fetch data from database and update it with "new version".
Here I have some code:
Events:
Handlers:
That is roughly what I do and it works really well for me :)
Maybe you want to read this topic: http://our.umbraco.org/forum/developers/extending-umbraco/25925-Catch-Change-Of-Property-Value-In-Event.
I also think it's important to read this topic: http://www.aaron-powell.com/the-great-umbraco-api-misconception.
Jeroen
is working on a reply...