Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Groovy console help

Avatar

Level 2

Hi everyone,
I am using the Groovy Console in AEM to update a custom property demo:status to "archieved" for all pages under /content/demo/en/archive that have a cq:template of myproject/components/page/article.
Here is the script: 

def rootPath = "/content/my-site/en/archive"
def resourceResolver = resourceResolverFactory.getServiceResourceResolver(null)
def session = resourceResolver.adaptTo(Session)

def query = "SELECT * FROM [cq:Page] AS s WHERE ISDESCENDANTNODE([${rootPath}]) AND s.[cq:template] = 'myproject/components/page/article'"
def result = session.workspace.queryManager.createQuery(query, "JCR-SQL2").execute()

result.nodes.each { node ->
def contentNode = node.getNode("jcr:content")
contentNode.setProperty("myProject:status", "archived")
println "Updated: ${node.path}"
}

session.save()

 

But I keep getting errors: javax.jcr.PathNotFoundException: jcr:content Can someone help me understand what’s wrong here?

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Vishal_Kagde,

You don’t need to manually get a ResourceResolver - Groovy Console already runs with one.

Try this:

def rootPath = "/content/my-site/en/archive"
def templatePath = "/conf/myproject/settings/wcm/templates/article"  // Update if full path is needed

def resources = getPageManager().getPage(rootPath)
    .listChildren()
    .findAll { page ->
        def content = page.contentResource
        content != null && content.getValueMap()["cq:template"] == templatePath
    }

resources.each { page ->
    def content = page.contentResource
    def modifiableMap = content.adaptTo(com.day.cq.commons.jcr.JcrUtil).getModifiableValueMap(content.resourceResolver, content.path)
    modifiableMap["myProject:status"] = "archived"
    println "Updated: ${page.path}"
}

resourceResolver.commit()

Santosh Sai

AEM BlogsLinkedIn


View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @Vishal_Kagde,

You don’t need to manually get a ResourceResolver - Groovy Console already runs with one.

Try this:

def rootPath = "/content/my-site/en/archive"
def templatePath = "/conf/myproject/settings/wcm/templates/article"  // Update if full path is needed

def resources = getPageManager().getPage(rootPath)
    .listChildren()
    .findAll { page ->
        def content = page.contentResource
        content != null && content.getValueMap()["cq:template"] == templatePath
    }

resources.each { page ->
    def content = page.contentResource
    def modifiableMap = content.adaptTo(com.day.cq.commons.jcr.JcrUtil).getModifiableValueMap(content.resourceResolver, content.path)
    modifiableMap["myProject:status"] = "archived"
    println "Updated: ${page.path}"
}

resourceResolver.commit()

Santosh Sai

AEM BlogsLinkedIn


Avatar

Level 2

Thanks,  it worked. Just wanted to share a small improvement I made in the simplified version using [cq:PageContent], I added a null check for node and myProject:status just to be safe in case some nodes were partially created or missing properties.