Expand my Community achievements bar.

SOLVED

update the page property for all pages using groovy script

Avatar

Level 4

Hloo all,

Can someone help me here update the page property for all pages using groovy script

1 Accepted Solution

Avatar

Correct answer by
Level 4

hi @Shiv_Prakash_Patel ,

need to update/change this path in all pages using groovy script

vinuu123_0-1685017258869.png

 

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @vinuu123 ,

Please use below groovy code to update the page property.

In this you can update the root page path, property name and value.

import javax.jcr.Node;

getNode('/content/learning').recurse { resourceNode ->
    if (resourceNode.hasProperty('jcr:primaryType')) {
        def primaryType = resourceNode.getProperty('jcr:primaryType').string;
        if(primaryType.equals('cq:PageContent')){
             resourceNode.setProperty('customProperty', 'customValue');
             resourceNode.getSession().save();
        }
    }
}
println('All Page property updated !!!');

Regards,

Shiv

 

Shiv Prakash

Avatar

Correct answer by
Level 4

hi @Shiv_Prakash_Patel ,

need to update/change this path in all pages using groovy script

vinuu123_0-1685017258869.png

 

Avatar

Community Advisor

Update the above code with below line. You can also change the value /conf/we-retail/settings/wcm/segments to your project specific.

resourceNode.setProperty('cq:contextHubSegmentsPath', '/conf/we-retail/settings/wcm/segments');

Regards,

Shiv

Shiv Prakash

Avatar

Level 4

import javax.jcr.Node;

getNode('/content/project').recurse {
resourceNode ->
if (resourceNode.hasProperty('cq:test')) {
resourceNode.setProperty('cq:test', 'new text');
resourceNode.getSession().save();
}
}