Copied to clipboard

Flag this post as spam?

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


  • Sergio 73 posts 93 karma points
    Sep 06, 2011 @ 10:59
    Sergio
    0

    New Items vs Updates. ¿VersionDate vs CreateDateTime?

    Hi,

    I need to detect when a document it´s been created or it´s been updated (AfterSave event). I´m trying to check this using VersionDate but this date it´s always minor than CreateDateTime.

    I can´t use the AfterNew event because I need to access to the URL property and it´s not available until the document has been saved.

    Any idea?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 06, 2011 @ 14:32
    Tom Fulton
    0

    Hi,

    So you are wanting to detect if this is the first time the document has been saved or not from the AfterSave event?

    I have seen (and used) other reccomendations to add a new property to your doctype, of type label, called something like isNew.  On Save, if the property is empty, you know it's new and you can set it to "1".  Then on subsequent saves you'll know it's an update since the property is filled out.  Not the cleanest but it works!

    Also, FYI, I don't think the URL will be available on the *first* AfterSave, I don't think it will be available until AfterUpdateDocumentCache (happens after AfterPublish)

    -Tom

  • Sergio 73 posts 93 karma points
    Sep 06, 2011 @ 15:46
    Sergio
    0

    Thanks Tom.

    Finally what I´ve done is to check if the document has relations because is one of the custom actions that I execute in the workflow the first time.

    About URL, is there any other posibility to get it if a document hasn´t been published before? I guess I can get it using the path property and translating the id´s but I´d like to know if there is an easier and smarter way.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 06, 2011 @ 15:50
    Tom Fulton
    0

    Hi,

    The relations bit sounds good, as long as you're calling it on a later event since you can't control the order your handlers will execute within the same event.

    Unfortunately the node doesn't actually get a URL generated until after it is published - so you wouldn't be able to get it before this happens.

    However, you can "guess" what the URL will be once it's published.  There was actually an extension added to uComponents called GuessNiceUrl that can guess the URL of an unpublished node.  See this page under New XSLT Extensions -> URLs:  added "GuessNiceUrl", which predicts the NiceUrl of an unpublished node!

    -Tom

  • Sergio 73 posts 93 karma points
    Sep 06, 2011 @ 16:03
    Sergio
    0

    I´ll check it.

    Thanks again Tom!

Please Sign in or register to post replies

Write your reply to:

Draft