cancel
Showing results for 
Search instead for 
Did you mean: 

Start Workflow Java

jmurias
Champ in-the-making
Champ in-the-making
Hi,
We need to start a Workflow from Java (from server, not from client. Javascript is not useful for us). We have read a lot but we aren´t able to do this.
Can anyone explain step by step how to start a Workflow from Java?
Thanks in advance!
8 REPLIES 8

bisana
Champ on-the-rise
Champ on-the-rise
I am confused over here.
by  mentioning Server did you mean that you want to start a workflow from Alfresco server and you dont want any coding for that part
If so, yes you can have workflow defined for Documents, or you can start work flow and later add documents to it
Please check the section "Mytask"  in that "MyTask" on the right side you can see a button to start work flow

jmurias
Champ in-the-making
Champ in-the-making
Hi bisana!

With "from Server" I want to say that the code we need is Java, not Javascript (Javascript is executed from clientside).
I need to start a Workflow using Java code but I´m not able to do this.

I have read the REST API documentation (we can invoque URLs from Java) but I haven´t found the way to do this… I have found how to stop workflow, delete workflow, but I´m not able to start a Workflow.

Thanks!

dranakan
Champ on-the-rise
Champ on-the-rise
Hi,

Take a look here : http://forums.alfresco.com/en/viewtopic.php?f=34&t=16989
Perhaps some changes are needed to start activity worfklow.

Good luck

jmurias
Champ in-the-making
Champ in-the-making
Hi Dranakan,

I read that post a week ago.

I don´t know how "WorkflowDefinition", "WorkflowPath", … classes are implemented… That´s a very "quick" explanation for me. I need a "step by step" explanation. I have read lots of post and nobody is able to do that. There are a lots of post asking for this and there are no replies…

The first thing I need to know is if is possible to start a workflow from Java and if it´s possible, a step by step "how to…". I think many people will appreciate it.

Thank you very much for the reply!

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Try this. Note you'll have to change the workflow definition name to the one you want to start.


        // Create the workflow with the newly created node as an item of the workflow
        List<WorkflowDefinition> workflows = workflowService.getAllDefinitionsByName("activiti$LoanRequestProcess"); // This could be "jbpm$LoanRequestProcess"
        WorkflowDefinition workflow = workflows.get(0); // Assume it is there
       
        // Set the workflow package
        // this contains the files within the workflow
        NodeRef workflowPackage = workflowService.createPackage(null);
        ChildAssociationRef childAssoc = nodeService.getPrimaryParent(nodeRef);
        this.nodeService.addChild(workflowPackage, nodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, childAssoc.getQName());
       
        // Set the parameters for the workflow
        Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
        parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
        parameters.put(WorkflowModel.ASSOC_ASSIGNEE, this.personService.getPerson("admin"));
       
        WorkflowPath workflowPath = workflowService.startWorkflow(workflow.getId(), parameters);

Adei

jmurias
Champ in-the-making
Champ in-the-making
Hi amandaluniz_z,

That´s exactly what I need.

I´m looking for documentation and I have found the API Documentation but I have some issues:

Where do I specify the URL to Alfresco server?
How do I initiate workflowService var?

I know I need the ticket and that isn´t problem. I send the user and password and I get the ticket.

Thank you very much for the reply!

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Alfresco is based on Spring. So that code could go in a spring bean to which you inject the different objects via spring.

Let's say you want to implement it in a Java backed webscript, check this samples which help how to achieve so.

Adei

jmurias
Champ in-the-making
Champ in-the-making
Thank you very much!