cancel
Showing results for 
Search instead for 
Did you mean: 

Delete Associated Workflows after document has been deleted

abbask01
Star Collaborator
Star Collaborator

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();
   });
}

Regards,
Abbas
1 ACCEPTED ANSWER

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.

View answer in original post

8 REPLIES 8

krutik_jayswal
Elite Collaborator
Elite Collaborator

Try implementing the same thing in beforeDeleteNode Policy .

sanjaybandhniya
Elite Collaborator
Elite Collaborator

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

Contcentric

abbask01
Star Collaborator
Star Collaborator

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.

Regards,
Abbas

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

Regards,
Abbas

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

Contcentric

Regards,
Vidhi

thanks for the code sample. i'll try and update here

Regards,
Abbas

Hello @abbask01 , Did you manage to delete the associated workflows? I want to implement the same thing, could you please help me with that?