How to retrieve the date of the first timeline entry for a page in AEM code base and display it with other details when author selects the page ? | Community
Skip to main content
Nilesh_Mali
Level 3
January 15, 2025
Solved

How to retrieve the date of the first timeline entry for a page in AEM code base and display it with other details when author selects the page ?

  • January 15, 2025
  • 3 replies
  • 635 views

Retrieve the date of the first timeline entry for a page in AEM code base and display it with other details when author selects the page. 

Or store first timeline entry date inside jcr:content with other page details

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 Nilesh_Mali

@kautuk_sahni  Discovered a solution

 

Accessing Timeline Data via PageManager API
AEM stores page modification history in the **PageManager** API. By leveraging this API, we can retrieve the first recorded modification date of a page.


Implementation

1. Backend: Servlet to Fetch Timeline Entries
A servlet was created to iterate through timeline entries and retrieve the earliest available creation date.

JSONArray timelineEntries = new JSONArray(); Iterator<Resource> timelineIterator = page.getContentResource().listChildren(); while (timelineIterator.hasNext()) { Resource timelineResource = timelineIterator.next(); String created = timelineResource.getValueMap().get("jcr:created", String.class); if (created != null) { JSONObject entry = new JSONObject(); entry.put("created", created); timelineEntries.put(entry); break; // Fetch only the first entry } }

 

2. Frontend: Displaying Timeline Data
A simple JavaScript snippet was implemented to fetch and display the first timeline entry on the frontend.

 

$(document).ready(function () { const pagePath = window.location.pathname; $.ajax({ url: "/bin/timeline", type: "GET", data: { path: pagePath }, success: function (data) { if (data.timeline.length > 0) { alert("Page First Created Date: " + data.timeline[0].created); } else { alert("No timeline entries found."); } }, error: function () { alert("Failed to retrieve timeline data."); } }); });



This solution efficiently extracts and presents the first recorded creation date of an AEM page.

3 replies

Tethich
Community Advisor
Community Advisor
January 15, 2025

Hi @nilesh_mali 

 

I believe you can look how this is handling it:

/libs/cq/gui/components/coral/common/admin/timeline/events/version

 

You can start from the version.jsp.

AmitVishwakarma
Community Advisor
Community Advisor
January 19, 2025
  1. Retrieve the First Timeline Entry Date: Query the page’s version history (jcr:versionHistory) and get the creation date of the first version.

  2. Store the Date in jcr:content: Save the date as a property (firstTimelineEntryDate) in the page's jcr:content node for easy access.

  3. Display in Dialog: Create a custom dialog to show the firstTimelineEntryDate property using a read-only field in AEM authoring interface.

This way, the first timeline entry date is easily accessible and stored with other page details.

kautuk_sahni
Community Manager
Community Manager
January 27, 2025

@nilesh_mali Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni
Nilesh_Mali
Nilesh_MaliAuthorAccepted solution
Level 3
February 3, 2025

@kautuk_sahni  Discovered a solution

 

Accessing Timeline Data via PageManager API
AEM stores page modification history in the **PageManager** API. By leveraging this API, we can retrieve the first recorded modification date of a page.


Implementation

1. Backend: Servlet to Fetch Timeline Entries
A servlet was created to iterate through timeline entries and retrieve the earliest available creation date.

JSONArray timelineEntries = new JSONArray(); Iterator<Resource> timelineIterator = page.getContentResource().listChildren(); while (timelineIterator.hasNext()) { Resource timelineResource = timelineIterator.next(); String created = timelineResource.getValueMap().get("jcr:created", String.class); if (created != null) { JSONObject entry = new JSONObject(); entry.put("created", created); timelineEntries.put(entry); break; // Fetch only the first entry } }

 

2. Frontend: Displaying Timeline Data
A simple JavaScript snippet was implemented to fetch and display the first timeline entry on the frontend.

 

$(document).ready(function () { const pagePath = window.location.pathname; $.ajax({ url: "/bin/timeline", type: "GET", data: { path: pagePath }, success: function (data) { if (data.timeline.length > 0) { alert("Page First Created Date: " + data.timeline[0].created); } else { alert("No timeline entries found."); } }, error: function () { alert("Failed to retrieve timeline data."); } }); });



This solution efficiently extracts and presents the first recorded creation date of an AEM page.