I have a requirement that if a document has been deleted in the repository then all the workflow that are associated with it should get deleted (each workflow package will always have a single document). Originally, on delete of a document the workflow is left in a hanging state and the reference of the document gets removed from the workflow side (bpm_package).
I tried to implement this by using rule/action (items are deleted or leave this folder) - was able to find workflows in js and cancel them, but it does not delete the document nor the workflow. on checking the XHR request i was able to find out that a concurrency exception occurs between the action and onDelete policy.
how do i delete/cancel/close the associated workflows of a document
PFB script to cancel workflow
/**
* js function call on 'onDeleteNode' to cancel all running workflows
*/
function cancelWorkflow() {
var document = behaviour.args[0];
logger.warn("doc: " + document.name);document.activeWorkflows.forEach(function(activeWf) {
activeWf.cancel(); / / also tried activeWf.delete();
});
}
Try implementing the same thing in beforeDeleteNode Policy .
You need to create Behavior/Policie to achieve this task.
http://docs.alfresco.com/6.0/references/dev-extension-points-behaviors.html
You can use beforeDeleteNode/onDeleteNode behaviour and write logic here to delete workflow.
Thanks
Sanjay
Krutik Jayswal i tried get the same error in rest with beforeDeleteNode -> JavaException: org.springframework.dao.ConcurrencyFailureException: Child association not found: 2178. A concurrency violation is likely.↵This can also occur if code reacts to 'beforeDelete' callbacks and pre-emptively deletes associations ↵that are about to be cascade-deleted. The 'onDelete' phase then fails to delete the association.↵See links on issue ALF-12358.
Sanjay Bandhniya on firing with onDeleteNode event - unable to get the nodeRef on the document.
You have to combine both method in that policy.
beforeDeleteNode() will give the noderef and assign it as global variable use that noderef in onDeleteNode() method to delete that noderef.
as far as i know - behavior/policies does not work like that.
could you please show me with an example - like i've mentioned in my question
Hello Abbas,
You can can cancel workflow on delete document by using behaviour/policies. Please refer following example.
public void beforeDeleteNode(final NodeRef nodeRef) {
List<WorkflowInstance> activeWorkflow = serviceRegistry.getWorkflowService().getWorkflowsForContent(nodeRef,true);
for (WorkflowInstance w : activeWorkflow) {
wIds.add(w.getId());
}}
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived) {
if (wIds.size() > 0) {
serviceRegistry.getWorkflowService().cancelWorkflows(wIds);
}
wIds.clear();
}
I have achieved that scenario using above solution. If you find better solution please share.
Thanks
Vidhi
thanks for the code sample. i'll try and update here
Hello @abbask01 , Did you manage to delete the associated workflows? I want to implement the same thing, could you please help me with that?
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.