Expand my Community achievements bar.

SOLVED

Page Manipulation operations

Avatar

Level 9

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.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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

View solution in original post

5 Replies

Avatar

Correct answer by
Level 2

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

Avatar

Level 3

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

Avatar

Level 9

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.

Avatar

Level 9

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.