Retrieve workflow definition based on workflow instance?

cancel
Showing results for 
Search instead for 
Did you mean: 
jacek_pater
Active Member

Retrieve workflow definition based on workflow instance?

[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
krutik_jayswal
Senior Member II

Re: Retrieve workflow definition based on workflow instance?

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 

jacek_pater
Active Member

Re: Retrieve workflow definition based on workflow instance?

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