Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Trying to implement a check to see if a content item has ie changed name. Hooked into ContentService.Saving and Saved events. Item is not published, so no version exists. Thought that one could grab the item from the db again to compare whats stored and what the new "version" that comes with e.SavedEntities. Bummer, geting the item using same ContentService suing GetById only reflects that same "version" has the e.SavedEntities has.
So how do I get the previous values of a Content item? IsDirty and IsPropertyDirty doesnt work, as I need the old value and the new value.
I would assume you can use contentService.GetByVersion(id). When you are in the Saving event the new properties haven't been persisted yet and the Version hasn't been updated yet (whether the version number is actually updated depends on it being a SaveAndPublish or just Save and whether the previous version was Published). But either way within the Saving event use sender.GetByVersion(content.Version); this should give you the old values which you can then compare to the content passed into the Saving event.
Hmm, will check but I think you dont have any other version if the item is not yet published.
Yea, but that shouldn't matter as the GetByVersion method is retreiving the previous (or well current) version directly from the db while you have the new values in memory.I haven't tested this, so I don't know for sure. But I'm assuming it will :)
Ok, so I can get the "same" version but from db directly?
Yes, I believe that should be possible because non of the new values has been persisted to the db yet. The transaction to persist is started after the Saving event.
Thanks Morten, just what I needed :-)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted