Need help with workflow in Alfresco
Posted
by Scott Gartner
on Stack Overflow
See other posts from Stack Overflow
or by Scott Gartner
Published on 2010-04-23T22:49:25Z
Indexed on
2010/04/23
22:53 UTC
Read the original article
Hit count: 633
Hello SO community,
I haven't had any luck getting help in the Alfresco forums, and I'm hoping for more here. We are building an application based on Alfresco and jBPM and I have defined a workflow, but I have either defined it wrong or am missing something or there are bugs in Alfresco integration with jBPM and I need help figuring out which and fixing it. Here is the problem:
I have an advanced workflow and I am trying to launch it from JavaScript. Here is the code I'm using to start the workflow:
var nodeId = args.nodeid;
var document = search.findNode("workspace://SpacesStore/" + nodeId);
var workflowAction = actions.create("start-workflow");
workflowAction.parameters.workflowName = "jbpm$nmwf:MyWorkflow";
workflowAction.parameters["bpm:workflowDescription"] = "Please edit: " + document.name;
workflowAction.parameters["bpm:assignees"] = [people.getPerson("admin"), people.getPerson("andyg")];
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflowAction.parameters["bpm:workflowDueDate"] = futureDate;
workflowAction.execute(document);
This runs fine and e-mail sent from the start node's default transition fires just fine. However, when I go looking for the workflow in my task list it is not there, but it is in my completed task list. The default transition (the only transition) from the start node points at a task node which has four transitions.
There are 8 tasks and 22 transitions in the workflow. When I use the workflow console to start the workflow and end the start task, it properly follows the default start node transition to the next task. The new task shows up in "show tasks" but does not show up in "show my tasks" (apparently because the task was marked completed for some reason, though it is not in the "end" node). The task is:
task id: jbpm$111 , name: nmwf:submitInEditing , properties: 18
If I do "show transitions" it looks just as I would expect:
path: jbpm$62-@ , node: In Editing , active: true
task id: jbpm$111 , name: nmwf:submitInEditing, title: submitInEditing title , desc: submitInEditing description , properties: 18
transition id: Submit for Approval , title: Submit for Approval
transition id: Request Copyediting Review , title: Request Copyediting Review
transition id: Request Legal Review , title: Request Legal Review
transition id: Request Review , title: Request Review
I don't want to post the entire workflow as it's large, but here are the first two nodes:
First the swimlanes:
<swimlane name="initiator"></swimlane>
<swimlane name="Content Providers">
<assignment actor-id="Content Providers">
<actor>#{bpm_assignees}</actor>
</assignment>
</swimlane>
Now the nodes:
<start-state name="start">
<task name="nmwf:submitTask" swimlane="initiator"/>
<transition name="" to="In Editing">
<action>
<runas>admin</runas>
<script>
/* Code to send e-mail that a new workflow was started. I get this e-mail. */
</script>
</action>
</transition>
</start-state>
<task-node name="In Editing">
<task name="nmwf:submitInEditing" swimlane="Content Providers" />
<!-- I put e-mail sending code in each of these transitions, but none are firing. -->
<transition to="In Approval" name="Submit for Approval"></transition>
<transition to="In Copyediting" name="Request Copyediting Review"></transition>
<transition to="In Legal Review" name="Request Legal Review"></transition>
<transition to="In Review" name="Request Review"></transition>
</task-node>
Here is the model for these two nodes:
<type name="nmwf:submitTask">
<parent>bpm:startTask</parent>
<mandatory-aspects>
<aspect>bpm:assignees</aspect>
</mandatory-aspects>
</type>
<type name="nmwf:submitInEditing">
<parent>bpm:workflowTask</parent>
<mandatory-aspects>
<aspect>bpm:assignees</aspect>
</mandatory-aspects>
</type>
Here is a pseudo-log of running the workflow in the workflow console:
:: deploy alfresco/extension/workflow/processdefinition.xml
deployed definition id: jbpm$69 , name: jbpm$nmwf:MyWorkflow , title: nmwf:MyWorkflow , version: 28
:: var bpm:assignees* person admin,andyg
set var {http://www.alfresco.org/model/bpm/1.0}assignees = [workspace://SpacesStore/73cf1b28-21aa-40ca-9dde-1cff492d0268, workspace://SpacesStore/03297e91-0b89-4db6-b764-5ada2d167424]
:: var bpm:package package 1
set var {http://www.alfresco.org/model/bpm/1.0}package = workspace://SpacesStore/6e2bbbbd-b728-4403-be37-dfce55a83641
:: start bpm:assignees bpm:package
started workflow id: jbpm$63 , def: nmwf:MyWorkflow
path: jbpm$63-@ , node: start , active: true
task id: jbpm$112 , name: nmwf:submitTask, title: submitTask title , desc: submitTask description , properties: 16
transition id: [default] , title: Task Done
:: show transitions
path: jbpm$63-@ , node: start , active: true
task id: jbpm$112 , name: nmwf:submitTask, title: submitTask title , desc: submitTask description , properties: 17
transition id: [default] , title: Task Done
:: end task jbpm$112
signal sent - path id: jbpm$63-@
path: jbpm$63-@ , node: In Editing , active: true
task id: jbpm$113 , name: nmwf:submitInEditing, title: submitInEditing title , desc: submitInEditing description , properties: 17
transition id: Submit for Approval , title: Submit for Approval
transition id: Request Copyediting Review , title: Request Copyediting Review
transition id: Request Legal Review , title: Request Legal Review
transition id: Request Review , title: Request Review
:: show tasks
task id: jbpm$113 , name: nmwf:submitInEditing , properties: 18
:: show my tasks
admin:
[there is no output here]
I have been making the assumption that the bpm:assignees that I am setting before starting the workflow initially are getting passed to the first task node "In Editing". Clearly the assignees are on the task object and not on the workflow object. I added the assignees aspect to the start-state task so that it could hold them (after I had a problem; initially they were not there) and possibly they are still sitting there, but the start-state has ended before I even get control back from the web script (not that it would help if it wasn't ended, I need it to be in "In Editing" as the start-state is only used to log that the workflow was started).
It has always confused me that the properties that I need to set on each task need to be requested before the task is entered (when you choose a transition you must provide the data for the next task before you can actually move to the next task as you have to validate that you have all of the required data first and then signal the transition). However, the code to start the workflow is asynchronous and therefore does not return either the started workflow or the current task (which in my case would be "In Editing"). So, either way you cannot set variables such as bpm:assignees and bpm:dueDate.
I wonder if this is the problem with the user task list. I'm setting the assignees in the property list, but maybe those assignees are going to the start-state task and are not getting passed to the "In Editing" task?
Note that this is my first jBPM workflow, so please don't assume I know what I'm doing. If you see something that looks off, it probably is and I just don't know it.
Thanks in advance for any advice or help,
© Stack Overflow or respective owner