How can I get the published date of a page in AEM? | Community
Skip to main content
Level 4
April 15, 2024
Solved

How can I get the published date of a page in AEM?

  • April 15, 2024
  • 1 reply
  • 4634 views

Hello I have a sling java model for component in a page, what I want to do is to take the publish date (this means, the date when you create a page in AEM and click into the publish button)

According to the research that I do, the value of the date of publication of the page of AEM is in the crx and is this one: cq:LastReplicated

This is obtained with the following java code:

 

@586265 @Named("jcr:content/cq:lastReplicated") private Date publishedDate

 

I have used it before to obtain the creation date of a page (jcr:created) (that is when you create a page in AEM regardless of whether it is published or not) and the code is the next one:

@586265 @Named("jcr:created") private Date createdDate

Unlike when I only obtained the date of creation of the page, here we notice that the date of publication is inside another node (jcr:content)

 


The code has a conditional that if it doesn’t find the date of publication of the page it uses the date of creation of the page (jcr:created) when we test the code I see that it only uses the date of creation of the page, it doesn’t find the date of publication of the page.

 

Is there any other way to get the publication date in the java sling model?

 

Or the variable that I'm trying to obtain (cq:lastReplicated) is not the indicated one to obtain the date of publication?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by sravs

@aaron_dempwolff , You can inject current page object in your slingmodel as shown below.

 

@ScriptVariable private Page currentPage;

In the method 

ValueMap pageProperties = currentPage.getProperties();
Date lastReplicated = pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED, Date.class)

 Hope this helps!!

1 reply

sravs
Community Advisor
sravsCommunity AdvisorAccepted solution
Community Advisor
April 15, 2024

@aaron_dempwolff , You can inject current page object in your slingmodel as shown below.

 

@ScriptVariable private Page currentPage;

In the method 

ValueMap pageProperties = currentPage.getProperties();
Date lastReplicated = pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED, Date.class)

 Hope this helps!!

Level 4
April 16, 2024

Hey, It actually works, but for some reason, I tried this into localhost and dev environment and works, but when I deployed into stage (QA) doesn't work, do you know why?

Level 4
April 16, 2024

Is this issue happening for all the pages, please validate once. If not,  please make sure it is replicated which you are trying to check is published.
if the issue still persists even after you replicating the page, check in crx whether "cq:lastReplicated" property set or not. If not check your permissions.

 


Yes it is, this is the crx of how it look, even have the date of today that I make the republish