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!
Solved! Go to Solution.
Views
Replies
Total Likes
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:
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)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)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.
Session save and refresh
Sometimes, if you’re changing nodes in the same script, you need:
session.save()
session.refresh(false)Verify logs
Check error.log or replication.log for lines like:
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.
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:
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)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)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.
Session save and refresh
Sometimes, if you’re changing nodes in the same script, you need:
session.save()
session.refresh(false)Verify logs
Check error.log or replication.log for lines like:
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.
@SantoshSai thankss, verifying the replication agent fixed it, i was running it on my local.
Views
Replies
Total Likes
Views
Likes
Replies