cancel
Showing results for 
Search instead for 
Did you mean: 

Creating behavior for deleting associated workflow after document deletion

imanez1
Confirmed Champ
Confirmed Champ

Hello,

I want to create a behavior that cancels associated workflows after file deletion. After some research, I found out that I need to implement the following Behavior/Policie:

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

My problem is I don't know where or how to implement this, any help is appreciated.

2 REPLIES 2

angelborroy
Community Manager Community Manager
Community Manager

You can start with this tutorial on how to implement Alfresco behaviours:

https://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html

Hyland Developer Evangelist

Bryan-Pauls
Champ in-the-making
Champ in-the-making

Posting so remember to check incase someone finds a solution.