Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Brännmark 228 posts 280 karma points
    Apr 25, 2013 @ 13:37
    Anders Brännmark
    0

    Get stored Content item to compare with Content item on saving / saved events (6.0.3)?

    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.

    /Anders

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Apr 25, 2013 @ 15:19
    Morten Christensen
    0

    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.

    Makes sense?

    - Morten

  • Anders Brännmark 228 posts 280 karma points
    Apr 25, 2013 @ 15:21
    Anders Brännmark
    0

    Hmm, will check but I think you dont have any other version if the item is not yet published.

    /Anders

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Apr 25, 2013 @ 15:38
    Morten Christensen
    101

    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 :)

    - Morten

  • Anders Brännmark 228 posts 280 karma points
    Apr 26, 2013 @ 07:48
    Anders Brännmark
    0

    Ok, so I can get the "same" version but from db directly?

     

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Apr 26, 2013 @ 07:51
    Morten Christensen
    0

    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.

  • Anders Brännmark 228 posts 280 karma points
    Apr 26, 2013 @ 07:53
    Anders Brännmark
    0

    Ok, Thanks!

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Mar 24, 2015 @ 12:06
    Stefan Kip
    0

    Thanks Morten, just what I needed :-)

Please Sign in or register to post replies

Write your reply to:

Draft