cancel
Showing results for 
Search instead for 
Did you mean: 

how to manage workflows programmatically?

wps07032
Champ in-the-making
Champ in-the-making
Hi all,

Can someone shed some lights on how to manage (create, start, delete, get status and etc) workflows programmatically?  For instance, how to kick off the default "Review and Approval" workflow by using the Java API?  I've seen a code snippet in this forum which suggested to use "workflowService".  But how to create a new instance of it?

// Get a list of workflow definitions and search through them for the one we want.
// Not sure if this is the best way to do this, but it seems to work.
List<WorkflowDefinition> workflowDefs = workflowService.getDefinitions();
Iterator<WorkflowDefinition> workflowDefsIterator = workflowDefs.iterator();
WorkflowDefinition workflowDef = null;

// Get a handle to the required workflow.
while (workflowDefsIterator.hasNext()) {
   workflowDef = workflowDefsIterator.next();

   if (workflowDef.name.equals(JBPM_WORKFLOW_NAME)) {
      break;
   }
}

Thanks.
6 REPLIES 6

davidc
Star Contributor
Star Contributor
Take a look at WorkflowInterpreter.java, the implementation of the Workflow Console.  It demonstrates the invocation of all WorkflowService methods.

wps07032
Champ in-the-making
Champ in-the-making
Is it possible to use Web Services to perform the same tasks listed in WorkflowInterpreter?  If so, a sample (java) code would be great.
My apps is currently running on a different webapps container, so web services seems to be a cleaner way to access alfresco.  Any suggestions would be greatly appreciated.

Thanks.

davidc
Star Contributor
Star Contributor
No, we don't currently have a workflow web services api.

In HEAD, we do have an extended workflow javascript api for managing workflows, so you could build web scripts for remotely interacting with a workflow.

wps07032
Champ in-the-making
Champ in-the-making
Thanks for the confirmation.

Would anyone happen to have some sample web scripts for managing workflow that can be shared?

Thanks.

wps07032
Champ in-the-making
Champ in-the-making
Besides using workflow javascript api, is it possible to use ActionService to execute workflow tasks (e.g define workflow actions and call executeActions() on the actions)?  If so, can you provide some detail on how-to?  I really want to avoid calling web scripts and then calling URLConnection for getting the result back.

Thanks.

davidc
Star Contributor
Star Contributor
For remote access, you have Web Services or Web Scripts.  You can execute an action via Web Services, but you'll need to code Workflow actions specifically for your use-case.