cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve workflow definition based on workflow instance?

jacek_pater
Champ on-the-rise
Champ on-the-rise

[version: Alfresco Community 5.2]

I need to create functionality, which removes all active workflow instances but only for specified workflow definition.

For instance, document may be a part of many diffrent workflows, e.g.  "New Task", "Review and Approve" and so on. More, there may be lot of instances of each workflows active at the same time. I'd like to remove all instances  of  "Review and Approve" workflow but left "New Task" still active.

2 REPLIES 2

krutik_jayswal
Elite Collaborator
Elite Collaborator

You can create a webscript and check whether the workflows which are running on particular node.

private static final String[] ENABLE_WORKFLOW_LIST = {"New Task"};

List<WorkflowInstance> workflowInstanceList = workflowService.getWorkflowsForContent(nodeRef, true);
for (WorkflowInstance workflowInstance : workflowInstanceList) {

       //Make check for workflow something like below
       if (!Arrays.asList(WORKFLOW_LIST).contains(workflowInstance.getDefinition().getTitle())) {
   //Perform the action which you want to do
       }
}

If you dont know how to create webscript you can refer below link for more details.

Repository webscript in alfresco | Krutik Jayswal 

Thanks. I did it exactly like that. I just was wondering if there is some simpler method that does not require coding.