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.
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)
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.
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!
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?
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
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.
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
I´ll check it.
Thanks again Tom!
is working on a reply...