Hello everyone,
I would like to ask for some advice regarding monitoring copy-paste operations in the AEM toolbar.
My goal is to detect when a new node is created via copy-paste and then remove the onTime property from that new node.
However, I keep encountering an error on the jcr:content node saying that it cannot be found.
From my research, it seems that when the node is copied, the operation is not fully synchronized yet.
But when I check in CRXDE after the copy, I can see the target node clearly.
I have attached my code for reference.
Solved! Go to Solution.
Views
Replies
Total Likes
Thank you for your patient support.
I've found the root cause of the issue.
The problem was that the system user used in the image did not have the necessary permissions.
After adding the correct path permissions, the code in Image was able to successfully locate the copied node and remove the desired properties.
Thank you again for all your help. Much appreciated!
Hi @ryuushihou1990,
When AEM does a copy-paste via the Sites toolbar:
It first creates the node, triggering your listener.
The child nodes (like jcr:content
) might not be fully available yet.
Your code immediately attempts to access the full structure, leading to errors.
Instead of modifying the node directly in the ResourceChangeListener
, enqueue a delayed Job (Sling Job or Scheduler) that acts on the node after a few seconds, giving time for the copy to complete.
// In your listener:
jobManager.addJob("remove/onTime",
Collections.singletonMap("path", path));
Then create a Job Consumer to handle the property removal after a short delay.
If you prefer to stay within the listener, implement a retry with exponential backoff:
int retries = 3;
while (retries-- > 0) {
if (session.nodeExists(path)) {
Node node = session.getNode(path);
if (node.hasProperty("onTime")) {
node.getProperty("onTime").remove();
session.save();
}
break;
}
Thread.sleep(500); // wait before retry
}
This is not the most elegant approach but may work for limited cases. Use with caution.
jcr:content
DirectlyIn some scenarios, the copy-paste triggers on the top-level node (e.g., /content/site/en/page
), but the onTime
is inside jcr:content
.
So if your goal is to remove the onTime
from jcr:content
, modify:
Node node = session.getNode(path + "/jcr:content");
But again, only after ensuring the node exists (via retry or delay).
Hope that helps!
Hi @SantoshSai
Thank you very much for your detailed and thoughtful response.
I tried using the listener.png you provided to monitor the copy-paste operation, and I registered a delayed job(job.png ) to remove the onTime property. I also updated the target path to basePath + "/jcr:content".
However, after repackaging the bundle and performing the copy-paste operation again, I noticed from the log files that the job kept trying to find the jcr:content node, but it never seemed to be available.
In fact, I had previously tried a brute-force approach by looping indefinitely to wait for the node to appear, but even then, the target jcr:content node never showed up.
Views
Replies
Total Likes
Hi @SantoshSai,
Requesting you to pleases help @ryuushihou1990 with the follow up query.
Thank you for your patient support.
I've found the root cause of the issue.
The problem was that the system user used in the image did not have the necessary permissions.
After adding the correct path permissions, the code in Image was able to successfully locate the copied node and remove the desired properties.
Thank you again for all your help. Much appreciated!