Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to Copy AEM node one place to another location?

Avatar

Employee

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
5 Replies

Avatar

Community Advisor

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/JcrUt...

Avatar

Level 3

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

Avatar

Community Advisor

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

Avatar

Employee

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

Avatar

Correct answer by
Community Advisor