Issue with javscript that removes another node when a node is deleted.
function main() {
var parent = space.parent;
var parentOfParent = parent.parent;var staffnetFolder = companyhome.childByNamePath("Shared/Staffnet/" + parentOfParent.name + "/" + parent.name);
var pdf = staffnetFolder.childByNamePath(document.name + ".pdf");
if (pdf !== null) { pdf.remove(); }
}main();
Basically, when an item is created we have a rule to create a pdf of it in another space. When the item is deleted, I want to delete the pdf as well. It's finding the PDF successfully, but when I run the remove() on the pdf I get this error -
"message" : "JavaException: org.springframework.dao.ConcurrencyFailureException: Deleted 0 but expected 1"
Are you sure you are getting the right "other" document?
Try to print the noderef for both document (the one you are deleting) and pdf (the one you are trying to delete in response of the first one) objects.
When I output the two nodeRefs they are what they should be. When I try to use the code in another action (such as an update rule) it works and deletes the PDF. It just seems to be the delete action that is causing this problem.
I am not sure if this is also true for folder rules, as I have never tried to do what you are trying, but I know that when you are using behaviours, you have to use another approach, as described in this blog post Alfresco – Implementing delete behavior | Programming and So
The use case is basically the same, but using Java code.
Thank you Douglas - sorry if I'm misunderstanding. So you're saying that I should look into developing behaviours instead of putting the action as a rule and use this transactional logic? Or am I able to implement transactional logic in rule scripts?
I believe that would be the right thing to do.
Maybe this is caused by „retriggering“ the delete rule with pdf.remove()?
But I can‘t see from your question if the staffnet folder is also in the range of your delete rule...
I'm not sure if you get what you want with using "space", maybe document.parent - but that depends were your rule is anchored and if it's trigger in sub-spaces (the whole tree)
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.