def query = SQLQuery() <- my sql query
def result = query.execute()
result.nodes.each{node ->
node.setProperty(JcrConstants.JCR_TITLE, "new3")
I found all components with a certain resource type using groovy consoly, and I need to replace their titles with the titles of the pages in which this component is located.
I need to use parent node named jcr:content
Instead of "new3" i can use node.getParent().getParent().getParent().getProperty("jcr:title"),but pages can have different structures. So, how to find parent node by name ?
The idiomatic way to find the
Pagecontaining a resource would be viaPageManager#getContainingPage.Once you've got a
Pageobject, you can read the relevant title. Keep in mind that there are a few options to choose from:titlepageTitlenavigationTitleThey can map to different dialog fields in the Page properties and certain components may use them differently, sometimes using fallbacks from one to another in case a value is absent. Same goes for different page-level components which may or may not allow authors to set a given property.
The exact use should be pretty clear if you use AEM Core Components but custom components may need a bit of investigation, especially if you're dealing with a long-lived codebase.
If none of the titles is a good fit, you could use the
nameof the page which should match its node name in the repository.The
PageManageritself should be available as a default binding in the Groovy console, underpageManager. Alternatively, it can be adapted from aResourceResolver, e.g. if you need some custom permissions.