Obsolete Pages{{Obsolete}}
The official documentation is at: http://docs.alfresco.com
Back to Workflow Samples
This page provides an Alfresco Workflow Definition sample.
This samples demonstrates how workflow and a very simple document lifecycle can be integrated.
Mike Farman (Alfresco)
The workflow uses a Lifecycle aspect to define the document lifecycle. On start of the workflow, the aspect is applied to each document in the workflow package. As the workflow progresses, the lifecycle status (a property of the aspect) is adjusted to reflect the new lifecyce state. This is all implemented using Alfresco Javascript within the workflow process definition (jPDL).
TODO: provide .acp archive of all source
Filename: config/alfresco/extension/lifecycle-workflow-context.xml
<beans>
<bean id='lifecycle.workflowBootstrap' parent='workflowDeployer'>
<property name='workflowDefinitions'>
<list>
<props>
<prop key='engineId'>jbpm</prop>
<prop key='location'>alfresco/extension/lifecycle_processdefinition.xml</prop>
<prop key='mimetype'>text/xml</prop>
<prop key='redeploy'>false</prop>
</props>
</list>
</property>
<property name='models'>
<list>
<value>alfresco/extension/lifecycleModel.xml</value>
</list>
</property>
<property name='labels'>
<list>
<value>alfresco/extension/lifecycle-messages</value>
</list>
</property>
</bean>
</beans>
Filename: config/alfresco/extension/lifecycle_processdefinition.xml
<process-definition xmlns='urn:jbpm.org:jpdl-3.1' name='wfl:lifecycleapproval'>
<swimlane name='initiator' />
<start-state name='start'>
<task name='wf:submitReviewTask' swimlane='initiator' />
<event type='node-leave'>
<action class='org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript'>
<script>
for (var i = 0; i < bpm_package.children.length; i++)
{
if (!bpm_package.children[i].hasAspect('wfl:status'))
{
bpm_package.children[i].addAspect('wfl:status');
}
}
</script>
</action>
</event>
<transition name='' to='review' />
</start-state>
<swimlane name='reviewer'>
<assignment class='org.alfresco.repo.workflow.jbpm.AlfrescoAssignment'>
<actor>#{bpm_assignee}</actor>
</assignment>
</swimlane>
<task-node name='review'>
<event type='node-enter'>
<action class='org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript'>
<script>
for (var i = 0; i < bpm_package.children.length; i++)
{
bpm_package.children[i].properties['wfl:status'] = 'In Review';
bpm_package.children[i].save();
}
</script>
</action>
</event>
<task name='wf:reviewTask' swimlane='reviewer'>
<event type='task-create'>
<script>
if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
</script>
</event>
</task>
<transition name='reject' to='rejected' />
<transition name='approve' to='approved' />
</task-node>
<task-node name='rejected'>
<event type='node-enter'>
<action class='org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript'>
<script>
for (var i = 0; i < bpm_package.children.length; i++)
{
bpm_package.children[i].properties['wfl:status'] = 'Draft';
bpm_package.children[i].save();
}
</script>
</action>
</event>
<task name='wf:rejectedTask' swimlane='initiator' />
<transition name='' to='end' />
</task-node>
<task-node name='approved'>
<event type='node-enter'>
<action class='org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript'>
<script>
for (var i = 0; i < bpm_package.children.length; i++)
{
bpm_package.children[i].properties['wfl:status'] = 'Approved';
bpm_package.children[i].save();
}
</script>
</action>
</event>
<task name='wf:approvedTask' swimlane='initiator' />
<transition name='' to='end' />
</task-node>
<end-state name='end' />
<event type='process-end'>
<action class='org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript'>
<script>
if (cancelled)
{
for (var i = 0; i < bpm_package.children.length; i++)
{
if (bpm_package.children[0].hasAspect('wfl:status'))
{
bpm_package.children[i].properties['wfl:status'] = 'Draft';
bpm_package.children[i].save();
}
}
if (logger.isLoggingEnabled()) logger.log('Workflow cancelled, status reset to Draft');
}
else
{
if (logger.isLoggingEnabled()) logger.log('Workflow completed');
}
</script>
</action>
</event>
</process-definition>
Filename: config/alfresco/extension/lifecycleModel.xml
<model name='wfl:workflowlifecyclemodel' xmlns='http://www.alfresco.org/model/dictionary/1.0'>
<description>Workflow Lifecycle Model</description>
<author></author>
<version>1.0</version>
<imports>
<import uri='http://www.alfresco.org/model/dictionary/1.0' prefix='d' />
<import uri='http://www.alfresco.org/model/content/1.0' prefix='cm' />
</imports>
<namespaces>
<namespace uri='wfl.model' prefix='wfl' />
</namespaces>
<constraints>
<constraint name='wfl:status' type='LIST'>
<parameter name='allowedValues'>
<list>
<value>Draft</value>
<value>In Review</value>
<value>Approved</value>
</list>
</parameter>
</constraint>
</constraints>
<aspects>
<aspect name='wfl:status'>
<title>Status</title>
<properties>
<property name='wfl:status'>
<title>Status</title>
<type>d:text</type>
<default>Draft</default>
<constraints>
<constraint ref='wfl:status' />
</constraints>
</property>
</properties>
</aspect>
</aspects>
</model>
Filename: config/alfresco/extension/lifecycle-messages.properties
wfl_lifecycleapproval.workflow.title=Lifecycle Review & Approve
wfl_lifecycleapproval.workflow.description=Lifecycle Review & Approval workflow (Auto updates document status)
wfl_lifecycleapproval.node.review.transition.reject.title=Reject
wfl_lifecycleapproval.node.review.transition.reject.description=Reject
wfl_lifecycleapproval.node.review.transition.approve.title=Approve
wfl_lifecycleapproval.node.review.transition.approve.description=Approve
None required, as it relies on the review & approve web client task dialogs.
In addition to auto-versioning on content updates, Alfresco 3.2 introduces auto-versioning on property-only updates. This does mean that a piece of versionable content (ie. document that has versioning behaviour enabled) which particpates in the sample 'Lifecycle Review & Approval' workflow, may have versions auto-incremented simply by the update of the custom status property.
If this behaviour is not desired then auto-versioning for property-only updates can be disabled or the versionable aspect can be overridden to exclude this specific property (wfl:status).
Workflow
Workflow Samples
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.