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.
Pre-requisites:
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.
Implementation:
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.
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.
Implementation:
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]
Groovy script:
Output:
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.
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]
Groovy script:
Output:
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.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.