update the page property for all pages using groovy script | Community
Skip to main content
Level 3
May 25, 2023
Solved

update the page property for all pages using groovy script

  • May 25, 2023
  • 3 replies
  • 2327 views

Hloo all,

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

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 vinuu123

hi @shiv_prakash_patel ,

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

 

3 replies

Shiv_Prakash_Patel
Community Advisor
Community Advisor
May 25, 2023

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
vinuu123AuthorAccepted solution
Level 3
May 25, 2023

hi @shiv_prakash_patel ,

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

 

Shiv_Prakash_Patel
Community Advisor
Community Advisor
May 25, 2023

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
rawvarun
Community Advisor
Community Advisor
May 25, 2023
Level 3
June 15, 2023

import javax.jcr.Node;

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