Expand my Community achievements bar.

SOLVED

Groovy script for Rename a page name with new page name

Avatar

Level 1

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. Screenshot (21)_LI.jpgwe want to change with groovy script.

1 Accepted Solution

Avatar

Correct answer by
Level 1

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++;
}
}

}

}

View solution in original post

3 Replies

Avatar

Community Advisor

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/Pa... 



Arun Patidar

Avatar

Correct answer by
Level 1

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++;
}
}

}

}