Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to add property and author a component for 2000 pages (same template) programmatically

Avatar

Level 2

I am using AEM 6.5.9. I have a requirement to redesign 2000 pages of the website which are using the same template.

 

As part of website redesign I need to 

1) add a property to the JCR for say 600 pages of the 2000

2) add a component to 2000 pages and display the output for the page

 

Please let me know the best approach for this using AEM programming. Thanks.

1 Accepted Solution

Avatar

Correct answer by
Adobe Champion
6 Replies

Avatar

Correct answer by
Adobe Champion

Create an on deploy script and use ACS On-Deploy pattern On-Deploy Scripts (adobe-consulting-services.github.io)

 

I've put sample code and examples here How to add property and author a component programmatically? - AEM.Design

Avatar

Level 2

Thanks for the reply @maxbarrass-anchora.

 

This approach looks good to add/modify properties. How do I author a component in 2000 pages, please suggest.

 

Thanks.

Avatar

Level 3

Hi @Lalitha_j 

There are many ways of doing this, if acs-tools package is installed in your AEM instance then this can be achieved through AEM Fiddle console. And adding a new component to the page can be achieved through ResourceResolver API. Write the business logic in Fiddle console and run your code.

Avatar

Adobe Champion

You can write a function that accepts a  resource and makes necessary structure under it. Do you want an example?

 

Side note. Also as this is On-Deploy code you can find examples of unit tests in the ACS repo. Other methods you will be shooting blind.

Avatar

Community Advisor

This can be done through Groovy Script

- Installation:

https://github.com/icfnext/aem-groovy-console

 

- Help Docs:

https://hashimkhan.in/aem-adobecq5-code-templates/groovy-script/

https://labs.tadigital.com/index.php/2018/12/18/groovy-script-in-aem/

 

 

It is similar to Java, and you can write a script and run through your groovy console on every environment.

Avatar

Community Advisor

@Lalitha_j Please try achieving your use-case using the Groovy script. 

Download the groovy console package from https://github.com/OlsonDigital/aem-groovy-console

Reference: https://labs.tadigital.com/index.php/2018/12/18/groovy-script-in-aem/