Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Update AEM Page Properties in bulk

Avatar

Level 1

Hi, We 100+ pages under sites and we have a requirement to update the fields in basic and also custom metadata fields. can you please let me know if there is a way to update the page metadata properties in bulk?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Anantha,

You can do this in multiple ways. 

1. Servlet - you can create a servlet that you would call to invoke OSGI backend operations on your AEM content pages. As an extra safety measure, you can create a content package from production, upload it into your development environment, and then run the servlet. Once when the content has been updated, package up the content and upload + install back into production.

2. Our of the box "edit" feature - From the Touch UI, you can select multiple pages, and then click on the edit button; this will allow you to edit page properties for more than 1 page, all together. 

3. AEM Groovy Script Console - with your groovy console plugin within your AEM environment, https://github.com/icfnext/aem-groovy-console, you can write a custom groovy script that you would call to invoke OSGI backend operations on your AEM content pages. As an extra safety measure, you can create a content package from production, upload it into your development environment, and then run the servlet. Once when the content has been updated, package up the content and upload + install back into production.

 

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

@Anantha,

You can do this in multiple ways. 

1. Servlet - you can create a servlet that you would call to invoke OSGI backend operations on your AEM content pages. As an extra safety measure, you can create a content package from production, upload it into your development environment, and then run the servlet. Once when the content has been updated, package up the content and upload + install back into production.

2. Our of the box "edit" feature - From the Touch UI, you can select multiple pages, and then click on the edit button; this will allow you to edit page properties for more than 1 page, all together. 

3. AEM Groovy Script Console - with your groovy console plugin within your AEM environment, https://github.com/icfnext/aem-groovy-console, you can write a custom groovy script that you would call to invoke OSGI backend operations on your AEM content pages. As an extra safety measure, you can create a content package from production, upload it into your development environment, and then run the servlet. Once when the content has been updated, package up the content and upload + install back into production.

 

 

Avatar

Community Advisor

Hi @Anantha 

 

You can create a Sling Servlet that can accept specific query parameters, which allows you to manipulate and change properties using CRUD API.

CRUD API - https://sling.apache.org/documentation/the-sling-engine/sling-api-crud-support.html

 

The servlet will accept parameters as "resourcePath", "propertyName", "propertyValue".
example: [POST] /bin/update-resource
resourcePath=/content/my-site/folder;
propertyName=testpropertyName;
propertyValue=true

 

Iterate through all the pages and then update, else you can do page wise also if the values are different:

public class SimpleServlet extends SlingAllMethodsServlet {

private static final long serialVersionUID = 1L;

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
ResourceResolver resourceResolver = getResourceResolver();
String path = Read from Request;
String propertyName = Read from Request;
String propertyValue = Read from Request;
Resource myResource = resourceResolver.getResource(path);
ModifiableValueMap properties = myResource.adaptTo(ModifiableValueMap.class);
properties.put(propertyName, propertyValue);
resourceResolver.commit();
}
}

 

Thanks!

Avatar

Community Advisor

Hey @Anantha, few suggestions:
1. If your pages have same sling:resourceTtpe i.e they use same page templates, then you can leverage OOTB bulk edit:

bilal_ahmad_0-1619678318820.png

 

2. Use Groovycripts to update the properties. For that you need to first write a query that will find out all your relevant pages(keeping page template or any other property(ies)) in mind. You need to be careful if you have excluded any path(s) in your custom index definition(oak:index) because sometimes we don't want certain page(s) or path(s) to show up when we query them.

Thanks,

Bilal.