Groovy script for Rename a page name with new page name | Community
Skip to main content
New Participant
May 25, 2022
Solved

Groovy script for Rename a page name with new page name

  • May 25, 2022
  • 3 replies
  • 1398 views

we changed a master page name from au-op to auop. now we want to display the new page name(auop) in redirect links, cta links, jcr:content & respective fields with it  but they are displaying the old name(au-op). we cannot change manually all the fields. we want to change with 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 AjayAkula

def statement = 'SELECT * from [nt:base] AS t where ISDESCENDANTNODE("/content/*") and contains(t.*, "cs-au-op")';
def query = session.getWorkspace().getQueryManager().createQuery(statement, 'JCR-SQL2');
def result = query.execute();
int count=0;
result.nodes.each { node ->
String nodePath = node.path;
def properties = node.getProperties();
properties.each { property ->
if (!property.isMultiple()) {
def propertyName = property.getName();
def propertyValue = property.getValue().getString();
if (propertyValue.contains('cs-au-op')) {
println nodePath+'/'+propertyName;
//println propertyValue;
def newPropertyValue = propertyValue.replaceAll("cs-au-op","cs-auop");
property.setValue(newPropertyValue);
session.save();
activate(node.path);
count++;
}
}

}

}

3 replies

AjayAkulaAuthorAccepted solution
New Participant
May 27, 2022

def statement = 'SELECT * from [nt:base] AS t where ISDESCENDANTNODE("/content/*") and contains(t.*, "cs-au-op")';
def query = session.getWorkspace().getQueryManager().createQuery(statement, 'JCR-SQL2');
def result = query.execute();
int count=0;
result.nodes.each { node ->
String nodePath = node.path;
def properties = node.getProperties();
properties.each { property ->
if (!property.isMultiple()) {
def propertyName = property.getName();
def propertyValue = property.getValue().getString();
if (propertyValue.contains('cs-au-op')) {
println nodePath+'/'+propertyName;
//println propertyValue;
def newPropertyValue = propertyValue.replaceAll("cs-au-op","cs-auop");
property.setValue(newPropertyValue);
session.save();
activate(node.path);
count++;
}
}

}

}

arunpatidar
New Participant
May 25, 2022

Hi,

You should do this with page move api, which could have taken care of references update as well.

https://developer.adobe.com/experience-manager/reference-materials/6-4/javadoc/com/day/cq/wcm/api/PageManager.html 

Arun Patidar
MayurSatav
New Participant
May 25, 2022