How to Copy AEM node one place to another location? | Community
Skip to main content
Employee
October 5, 2021
Solved

How to Copy AEM node one place to another location?

  • October 5, 2021
  • 3 replies
  • 7109 views

I need to copy an AEM JCR node source to destination. The following code is working but if that node already exists in the destination I'm getting an error:

 

String sourcePath="/content/dam/assets/content";

String destinationPath="/content/dam/Marketing/content";

Session session = resourceResolver.adaptTo(Session.class);

Workspace workspace = session.getWorkspace();

workspace.copy(sourcePath, destinationPath);

session.logout();

 

But the problem is that the content node already exists inside the folder "Marketing" so that it's only working on the first time. Once the content node is created I'm not able to copy/update the node but I need to replace each time without deleting the source node.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kiran_Vedantam

Hi @keerthana_h_n 

 

Please check this URL:

https://aemvardhan.wordpress.com/2017/02/24/how-to-copy-aem-node-tree-in-jcrcrx/

 

Also I see the same question here: https://stackoverflow.com/questions/42420255/how-to-copy-aem-node-one-place-to-another-location

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

3 replies

Kiran_Vedantam
Kiran_VedantamAccepted solution
New Participant
October 5, 2021
Dipti_Chauhan
New Participant
October 5, 2021

Hi @keerthana_h_n 

 If node already exist in destination path, You want to leave it as is or want to replace it with updated properties.

Thanks

Dipti

Employee
October 5, 2021

Hi @dipti_chauhan I want to replace the current node with updated properties if the node is already there.

lukasz-m
New Participant
October 5, 2021

Hi @keerthana_h_n, I am not sure if I understood your use case correctly, however please check copy method from com.day.cq.commons.jcr.JcrUtil [1]

 

[1] https://www.adobe.io/experience-manager/reference-materials/6-5/javadoc/com/day/cq/commons/jcr/JcrUtil.html#copy-javax.jcr.Node-javax.jcr.Node-java.lang.String-

New Participant
November 16, 2022

This worked very well to copy whole node from source location to destination.