Expand my Community achievements bar.

Get ready! An upgraded Experience League Community experience is coming in January.
SOLVED

Facing issue with activating DAM assets in Groovy script

Avatar

Level 2

 

Hi everyone,

I’m trying to activate DAM assets programmatically through a Groovy script in, but the code doesn’t seem to trigger replication as expected. It runs without errors, but the assets remain unpublished.

 

import com.day.cq.replication.Replicator
import com.day.cq.replication.ReplicationActionType
import javax.jcr.Session

def replicator = getService(Replicator)
def session = session as Session

def paths = [
"/content/dam/example-folder/image1.jpg",
"/content/dam/example-folder/image2.jpg"
]

paths.each { path ->
try {
replicator.replicate(session, ReplicationActionType.ACTIVATE, path)
println "Activated: ${path}"
} catch (Exception e) {
println "Error activating ${path}: ${e.message}"
}
}

 

I can see the logs printing Activated: path, but the assets don’t show up as published in AEM.
Has anyone faced this issue or know what might be missing here?

Thanks in advance for your help!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @NehaBa4,

For me, the script looks correct, but the issue is likely related to how replication is being triggered in your environment. A few things to check and adjust:

  1. Ensure you’re using a JCR session with enough privileges
    Make sure the session has replicate permission on the paths you’re trying to publish. If you’re running this from Groovy Console, try using an admin session:

    def session = resourceResolver.adaptTo(javax.jcr.Session)
  2. Use ReplicationOptions if running in AEMaaCS
    In AEMaaCS or cloud environments, using replication with options is often required:

    import com.day.cq.replication.ReplicationOptions
    
    def opts = new ReplicationOptions()
    opts.setSuppressStatusUpdate(true)
    replicator.replicate(session, ReplicationActionType.ACTIVATE, path, opts)
  3. Check replication agents
    Go to Tools -> Deployment -> Replication -> Agents on author, and ensure the publish agent is active and configured properly.
    If it’s disabled or not pointing to your publisher, the activation will silently succeed but not actually deliver content.

  4. Session save and refresh
    Sometimes, if you’re changing nodes in the same script, you need:

    session.save()
    session.refresh(false)
  5. Verify logs
    Check error.log or replication.log for lines like:

    *INFO* [JobHandler: /etc/replication/agents.author/publish]

    If you don’t see this, the job never reached the agent.

If everything looks fine but still doesn’t replicate, try wrapping the call inside a service user (via ResourceResolverFactory.getServiceResourceResolver()) instead of Groovy Console session - that often fixes permission issues in newer AEMaaCS environments.


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @NehaBa4,

For me, the script looks correct, but the issue is likely related to how replication is being triggered in your environment. A few things to check and adjust:

  1. Ensure you’re using a JCR session with enough privileges
    Make sure the session has replicate permission on the paths you’re trying to publish. If you’re running this from Groovy Console, try using an admin session:

    def session = resourceResolver.adaptTo(javax.jcr.Session)
  2. Use ReplicationOptions if running in AEMaaCS
    In AEMaaCS or cloud environments, using replication with options is often required:

    import com.day.cq.replication.ReplicationOptions
    
    def opts = new ReplicationOptions()
    opts.setSuppressStatusUpdate(true)
    replicator.replicate(session, ReplicationActionType.ACTIVATE, path, opts)
  3. Check replication agents
    Go to Tools -> Deployment -> Replication -> Agents on author, and ensure the publish agent is active and configured properly.
    If it’s disabled or not pointing to your publisher, the activation will silently succeed but not actually deliver content.

  4. Session save and refresh
    Sometimes, if you’re changing nodes in the same script, you need:

    session.save()
    session.refresh(false)
  5. Verify logs
    Check error.log or replication.log for lines like:

    *INFO* [JobHandler: /etc/replication/agents.author/publish]

    If you don’t see this, the job never reached the agent.

If everything looks fine but still doesn’t replicate, try wrapping the call inside a service user (via ResourceResolverFactory.getServiceResourceResolver()) instead of Groovy Console session - that often fixes permission issues in newer AEMaaCS environments.


Santosh Sai

AEM BlogsLinkedIn


Avatar

Level 2

@SantoshSai thankss, verifying the replication agent fixed it, i was running it on my local.