Développer ma barre des réalisations de la Communauté.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
RÉSOLU

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 ?

Avatar

Level 4

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

1 solution acceptée

Avatar

Réponse correcte par
Level 4

@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.

Voir la solution dans l'envoi d'origine

4 Replies

Avatar

Community Advisor

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.

Avatar

Community Advisor
  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.

Avatar

Administrator

@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

Avatar

Réponse correcte par
Level 4

@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.