Page Manipulation operations | Community
Skip to main content
New Participant
October 16, 2015
Solved

Page Manipulation operations

  • October 16, 2015
  • 5 replies
  • 2301 views

Hi All,

Suppose I want to delete two specific properties from a specific component, present on all pages in author.
Which would be the best way to do it. Any code snippet regarding this will be very helpful.

Any thoughts will be really helpful.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ANKUR_CHAUHAN

For doing this follow given steps - 

first you have to search all pages those contains this component & for doing this you can use search query as shown below - 

type=nt:unstructured
path=/content
property = cq:commerceType
property.value=product

This query will return all pages those contains a node having property cq:commerceType & value as product.

Second - Now just remove the properties from these result set resources by -

first adopt these resource into ModifiableValueMap this is a extension of ValueMap in AEM.

Then simply use map.put() method to change the value & the commit the resourceResolver using resourceResolver.commit() method.

It will do what you want.

Happy Coding

5 replies

ANKUR_CHAUHAN
ANKUR_CHAUHANAccepted solution
New Participant
October 16, 2015

For doing this follow given steps - 

first you have to search all pages those contains this component & for doing this you can use search query as shown below - 

type=nt:unstructured
path=/content
property = cq:commerceType
property.value=product

This query will return all pages those contains a node having property cq:commerceType & value as product.

Second - Now just remove the properties from these result set resources by -

first adopt these resource into ModifiableValueMap this is a extension of ValueMap in AEM.

Then simply use map.put() method to change the value & the commit the resourceResolver using resourceResolver.commit() method.

It will do what you want.

Happy Coding

Lokesh_Shivalingaiah
New Participant
October 16, 2015

You can write a simple service using JCR API to do that for you !

You can refer this on using JCR API

https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html

New Participant
October 16, 2015

My favorite tool for this type of thing is the groovy console. Makes doing large scale changes such as this a lot easier

https://github.com/Citytechinc/cq-groovy-console

askdctmAuthor
New Participant
October 16, 2015

Hi Bailey,

Thank you for your reply. 

Did go through the code, but was not able to understand much.

Do you have any other references/simple code, so that I get some understanding on this.

askdctmAuthor
New Participant
October 16, 2015

Hi Ankur,

Thanks a ton for your reply.

1] http://www.wemblog.com/2014/08/how-to-use-sessions-and-resource.html Looks like this has code similar to what you mentioned. Is that correct?

2] In the search query you provided(taking that as a reference), I want to remove property cq:commerceType from all the pages in author. That can be done based on the code provided in #1[above]?

Your thoughts/pointers will be really helpful.