In today’s world, most of the developers try to find the delta content manually in AEM by checking the timestamp of pages and assets and add these paths in the filers of AEM package. Though its not an incorrect way, but there are high chances of missing some pages or assets doing so. So, we have curated this article to help AEM developers find the pages and assets that has been created/modified during specific given time frame and automates the package creation process.
The AEM Groovy Console provides an interface for running Groovy scripts in Adobe Experience Manager. Scripts can be created and executed to manipulate content in the JCR, call OSGi services, or execute adhoc code using the AEM, Sling, or JCR APIs without any interruptions to AEM instance.
If you have ever come across a situation where in you need to create delta content packages in AEM instances, then this blog is for you. We are going to create and execute a groovy script which creates a series of content packages in package manager, which are modified or created over a specific date range.
Download and install the groovy console package, which is compatible with your AEM version. Below table shows the compatibility versions of AEM and Groovy Console.
|Groovy Console Version(s)||AEM Version(s)|
|15.x.x, 14.x.x, 13.x.x||6.3, 6.4, 6.5|
|6.x.x, 5.x.x||5.6 (CQ)|
|3.x.x||5.5, 5.4 (CQ)|
In order to find the delta content for a specific date range, we are going to use SQL2 query and find out if any new pages or assets have been created or any existing pages and assets have been modified in AEM instance. We are going to utilize the JCR properties like jcr:created and cq:lastModified in our SQL2 query.
Sample SQL2 Query:
SELECT * FROM [cq:PageContent] AS s WHERE ISDESCENDANTNODE([/content/nextrow]) AND ((s.[cq:lastModified] >= CAST(‘2020-07-28T16:00:00.000Z’ AS DATE) AND s.[cq:lastModified] <= CAST(‘2020-07-30T21:00:00.000Z’ AS DATE)) OR (s.[jcr:created] >= CAST(‘2020-07-28T16:00:00.000Z’ AS DATE) AND s.[jcr:created] <= CAST(‘2020-07-30T21:00:00.000Z’ AS DATE))) order by [cq:lastModified]
After we run the above groovy script, a series of content packages will get created in package manager. Go to package manager (http://localhost:4502/crx/packmgr/index.jsp) and build the content packages.
So as you may have noticed that Groovy scripts could be quite useful, easy to use, and very handy for any AEM developer to manipulate content in one go.