09-27-2017 12:35 PM
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"
09-27-2017 04:16 PM
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.
09-27-2017 04:30 PM
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.
09-27-2017 04:39 PM
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.
09-27-2017 04:55 PM
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?
09-27-2017 05:29 PM
I believe that would be the right thing to do.
05-10-2018 08:27 AM
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)
Explore our Alfresco products with the links below. Use labels to filter content by product module.