Friday, July 26, 2013

Creating Custom Workflow in Alfresco


Hi Every One,

          In this post, i am going to discuss what is workflow and how to create our own custom workflow in alfresco share

Workflow:
workflow consists of a sequence of connected steps where each step follows without delay or gap and ends just before the subsequent step may begin. It is a depiction of a sequence of operations, declared as work of a person or group, an organization of staff, or one or more simple or complex mechanisms. Workflow may be seen as any abstraction of real work. For control purposes, workflow may be a view of real work in a chosen aspect, thus serving as a virtual representation of actual work. The flow being described may refer to a document or product that is being transferred from one step to another.
Workflows may be viewed as one primitive building block to be combined with other parts of an organisation's structure such as information silos, teams, projects, policies and hierarchies.

In simple words flow where to go what and accepts and rejects, if accept it has to go some person ,rejects some other. these things will be there in workflow.

Adding new workflow in Alfresco: 
For this you need to add some XML files and edit some XML files.

Files to be added
1)BidFlow.bpmn20.xml( file name can be any thing but extension has to be .bpmn20.xml)
2)CustomModel.xml (file name can be any thing but extension has to be .xml)

Files to edit
3)share-workflow-form-config.xml
4)bootstrap-context.xml



Files to be added

BidFlow.bpmn20.xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="BidFlow" name="BidFlow" isExecutable="true">
<extensionElements>
<activiti:executionListener event="start"
class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
<activiti:field name="script">
<activiti:string>execution.setVariable('wf_EditorsGroup', groups.getGroup('Editors').getFullName());
            execution.setVariable('wf_CollaboratorsGroup', groups.getGroup('Collaborators').getFullName());
            execution.setVariable('wf_ContributorsGroup', groups.getGroup('Contributors').getFullName());
            execution.setVariable('wf_CoordinatorsGroup', groups.getGroup('Coordinators').getFullName());
         </activiti:string>

</activiti:field>
</activiti:executionListener>

</extensionElements>
    <startEvent id="startevent1" name="Start" activiti:candidateGroups="${wf_ContributorsGroup}" activiti:formKey="wf:BidFlow"></startEvent>
    <userTask id="EditorTask1" name="EditorTask1" activiti:candidateGroups="${wf_EditorsGroup}" activiti:formKey="wf:TestFloweditors">
     <extensionElements>
    <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
                 if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                 if (typeof bpm_comment != 'undefined') task.setVariable('bpm_comment', bpm_comment);
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>execution.setVariable('bpm_assignee', task.getVariable('bpm_assignee'));
                  execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
                execution.setVariable('wf_manager', person);
                execution.setVariable('bpm_dueDate', task.dueDate);
                execution.setVariable('bpm_priority', task.priority);
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
 
  </extensionElements>
 
    </userTask>
    <userTask id="CollaboratorTask1" name="CollaboratorTask1" activiti:candidateGroups="${wf_CollaboratorsGroup}" activiti:formKey="wf:TestFlowcollaborators">
      <extensionElements>
    <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
                 if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                 if (typeof bpm_comment != 'undefined') task.setVariable('bpm_comment', bpm_comment);
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
                  execution.setVariable('bpm_assignee', task.getVariable('bpm_assignee'));
                  execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
                execution.setVariable('wf_manager', person);
                execution.setVariable('bpm_dueDate', task.dueDate);
                execution.setVariable('bpm_priority', task.priority);

            </activiti:string>
          </activiti:field>
        </activiti:taskListener>

        </extensionElements>
    </userTask>
    <userTask id="EditorTask2" name="EditorTask2" activiti:candidateGroups="${wf_EditorsGroup}" activiti:formKey="wf:TestFloweditors">
     <extensionElements>
    <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
                 if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                 if (typeof bpm_comment != 'undefined') task.setVariable('bpm_comment', bpm_comment);
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
execution.setVariable('bpm_assignee', task.getVariable('bpm_assignee'));
                  execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
                execution.setVariable('wf_manager', person);
                execution.setVariable('bpm_dueDate', task.dueDate);
                execution.setVariable('bpm_priority', task.priority);
           </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        </extensionElements>  
    </userTask>
    <userTask id="CollaboratorTask2" name="CollaboratorTask2" activiti:candidateGroups="${wf_CollaboratorsGroup}" activiti:formKey="wf:TestFlowcollaborators">
     <extensionElements>
    <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
                 if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                 if (typeof bpm_comment != 'undefined') task.setVariable('bpm_comment', bpm_comment);
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
execution.setVariable('bpm_assignee', task.getVariable('bpm_assignee'));
                  execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
                execution.setVariable('wf_manager', person);
                execution.setVariable('bpm_dueDate', task.dueDate);
                execution.setVariable('bpm_priority', task.priority);
           </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        </extensionElements>  
    </userTask>
    <userTask id="CoordinatorTask" name="CoordinatorTask" activiti:candidateGroups="${wf_CoordinatorsGroup}" activiti:formKey="wf:TestFlowcoordinators"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="EditorTask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="EditorTask1" targetRef="CollaboratorTask1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="CollaboratorTask1" targetRef="EditorTask2"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="EditorTask2" targetRef="CollaboratorTask2"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="CollaboratorTask2" targetRef="CoordinatorTask"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="CoordinatorTask" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="BidFlow" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="50.0" y="80.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="EditorTask1" id="BPMNShape_EditorTask1">
        <omgdc:Bounds height="55.0" width="105.0" x="84.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="EditorTask2" id="BPMNShape_EditorTask2">
        <omgdc:Bounds height="55.0" width="105.0" x="400.0" y="320.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="CollaboratorTask1" id="BPMNShape_CollaboratorTask1">
        <omgdc:Bounds height="55.0" width="105.0" x="220.0" y="240.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="CoordinatorTask" id="BPMNShape_CoordinatorTask">
        <omgdc:Bounds height="55.0" width="105.0" x="680.0" y="123.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="CollaboratorTask2" id="BPMNShape_CollaboratorTask2">
        <omgdc:Bounds height="55.0" width="105.0" x="580.0" y="240.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="770.0" y="46.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="85.0" y="97.0"></omgdi:waypoint>
        <omgdi:waypoint x="136.0" y="97.0"></omgdi:waypoint>
        <omgdi:waypoint x="136.0" y="150.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="189.0" y="177.0"></omgdi:waypoint>
        <omgdi:waypoint x="272.0" y="177.0"></omgdi:waypoint>
        <omgdi:waypoint x="272.0" y="240.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="272.0" y="295.0"></omgdi:waypoint>
        <omgdi:waypoint x="272.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="400.0" y="347.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="452.0" y="320.0"></omgdi:waypoint>
        <omgdi:waypoint x="452.0" y="267.0"></omgdi:waypoint>
        <omgdi:waypoint x="580.0" y="267.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="685.0" y="267.0"></omgdi:waypoint>
        <omgdi:waypoint x="731.0" y="267.0"></omgdi:waypoint>
        <omgdi:waypoint x="732.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="732.0" y="123.0"></omgdi:waypoint>
        <omgdi:waypoint x="732.0" y="63.0"></omgdi:waypoint>
        <omgdi:waypoint x="770.0" y="63.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

This is the file where we add the actual workflow this has to be there in Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\workflow

Description about this workflow: this workflow we are getting all the group names and assigning work as follows
           1)contributor group fellow will stat the workflow.
            2)in first step started work will assigned to all the fellows there in editor group.
            3) from second step it will assigned to all the collaborator group fellows.
            4)from third to it will assigned to all the editor group fellows.
            5)from fourth to it will assigned to all the collaborator group fellows.
            6)fifth to it will assigned to coordinator.




custommodel.xml
<?xml version="1.0" encoding="UTF-8"?>

<model name="wf:workflowmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<!-- Import Alfresco System Definitions -->
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys" />
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
<!-- Import User Model Definitions -->
<import uri="http://www.alfresco.org/model/user/1.0" prefix="usr" />
<import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm" />
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/model/workflow/1.0" prefix="wf" />
</namespaces>
<types>
<type name="wf:BidFlow">
<parent>bpm:startTask</parent>

<mandatory-aspects>
<aspect>wf:workInfo</aspect>
</mandatory-aspects>

</type>
<type name="wf:TestFloweditors">
<parent>bpm:workflowTask</parent>

<!-- <overrides>

<property name="bpm:packageActionGroup">
<default>add_package_item_actions</default>
</property>

</overrides>
 -->
<mandatory-aspects>

<aspect>wf:workInfo</aspect>
</mandatory-aspects>
</type>
<type name="wf:TestFlowcontributors">
<parent>bpm:workflowTask</parent>

<overrides>

<property name="bpm:packageActionGroup">
<default>add_package_item_actions</default>
</property>

</overrides>

<mandatory-aspects>

<aspect>wf:workInfo</aspect>
</mandatory-aspects>
</type>

<type name="wf:TestFlowcollaborators">
<parent>bpm:workflowTask</parent>

<overrides>

<property name="bpm:packageActionGroup">
<default>add_package_item_actions</default>
</property>

</overrides>

<mandatory-aspects>
<aspect>wf:workInfo</aspect>
</mandatory-aspects>
</type>
<type name="wf:TestFlowcoordinators">
<parent>bpm:workflowTask</parent>

<overrides>

<property name="bpm:packageActionGroup">
<default>add_package_item_actions</default>
</property>

</overrides>

<mandatory-aspects>
<aspect>wf:workInfo</aspect>
</mandatory-aspects>
</type>

</types>
<aspects>

<aspect name="wf:workInfo">
<properties>
<property name="wf:workDescription">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
</aspect>

</aspects>

</model>

this model contains all the types and its's aspects this has to be there in
Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\workflow



This code needs to be added to corresponding files
share-workflow-form-config.xml
<!--for BidFlow-->
<config evaluator="string-compare" condition="activiti$BidFlow">
<forms>
<form>
<field-visibility>
<show id="bpm:workflowDescription" />
<show id="bpm:workflowDueDate" />
<show id="bpm:workflowPriority" />
<show id="wf:workDescription" />
<show id="packageItems" />
<show id="bpm:comment" />
<show id="bpm:sendEMailNotifications" />
</field-visibility>
<appearance>
<set id="" appearance="title" label-id="workflow.set.general" />
<set id="info" appearance=""
template="/org/alfresco/components/form/2-column-set.ftl" />
<set id="items" appearance="title" label-id="workflow.set.items" />
<set id="work" appearance="title" label-id="workflow.set.work" />
<set id="other" appearance="title" label-id="workflow.set.other" />
<set id="response" appearance="title" label-id="workflow.set.response" />

<field id="bpm:workflowDescription" label-id="workflow.field.message">
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="style">width: 95%</control-param>
</control>
</field>

<field id="bpm:workflowDueDate" label-id="workflow.field.due"
set="info" />
<field id="bpm:workflowPriority" label-id="workflow.field.priority"
set="info">
<control
template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
</field>


<field id="packageItems" set="items" />
<field id="wf:workDescription" set="work" />

<field id="bpm:sendEMailNotifications" set="other">
<control
template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" />
</field>

<field id="bpm:comment" label-id="workflow.field.comment"
set="response">
<control template="/org/alfresco/components/form/controls/textarea.ftl" />
</field>
</appearance>
</form>
</forms>
</config>

this file contains ShareUI for work flow, we need to add the UI components for our workflow this has to be there in
Alfresco\tomcat\webapps\share\WEB-INF\classes\alfresco


bootstrap-context.xml
         
<!--add this props tag in <property name="workflowDefinitions">-->
              <props>
                    <prop key="engineId">activiti</prop>
                    <prop key="location">alfresco/workflow/BidFlow.bpmn20.xml</prop>
                    <prop key="mimetype">text/xml</prop>
                    <prop key="redeploy">false</prop>
                </props>
<!--add this value tag in <property name="models">-->
<value>alfresco/workflow/custommodel.xml</value>
this file contains code to  our workflow in to server while starting the server
Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco


Vikram Vanama

16 comments:

  1. Good tutorial to create custom workflow.

    ReplyDelete
  2. Hi, I put the files at the right location and I rebooted tomcat. I can't see the new workflow in the the workflow list. Is there anything else to do ?

    ReplyDelete
  3. please share me more information how you doing and alfresco.log and share.log.

    ReplyDelete
  4. Thankyouuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

    ReplyDelete
  5. when u start the server it will deploy automatically through bootstrap-context.xml and u can deploy undeploy from this url
    "http://localhost:8080/alfresco/faces/jsp/admin/workflow-console.jsp"

    ReplyDelete
  6. Since I am using Alfresco Community Version,I couldn't find the file "share-workflow-form-config.xml" in the given path Alfresco\tomcat\webapps\share\WEB-INF\classes\alfresco.Could you please tell me how to deploy workflow in Alfresco community version?

    ReplyDelete
  7. yes, you recheck once file should be there in above location and which version of community edition you are using.

    ReplyDelete
  8. Hi, I put the files at the right location and I rebooted tomcat.I see the new workflow in the workflow list but when I start the workflow ,there’s an error
    This is the error:
    Workflow could not be started.
    org.alfresco.scripts.ScriptException: 06080023 Failed to execute supplied script: 06080022 TypeError: Cannot call method "getFullName" of null (AlfrescoJS#2)

    Thank you. Your help will be very much appreciated.

    ReplyDelete
  9. Hai Zeineb Akacha,

    you done every thing currect and you should create the groups in alfresco with name(Editors,Collaborators,Contributors,Coordinators). then you won't get above error.

    -Vikram

    ReplyDelete
  10. Hi vikram vanama ,
    I already create the groups in alfresco with name ((Editors,Collaborators,Contributors,Coordinators) but I still have the same error org.alfresco.scripts.ScriptException: 06080035 Failed to execute supplied script: 06080034 TypeError: Cannot call method "getFullName" of null (AlfrescoJS#2)

    ReplyDelete
    Replies
    1. after creating group you need to redepoly the workflow
      for redeploying login alfresco with admin and open this url in another tab localhost:8080/alfresco/faces/jsp/admin/workflow-console.jsp and in that give this command "undeploy definition name activiti$BidFlow" then restart the server. it will work for you and Re check the group names. you created.

      Delete
    2. This comment has been removed by the author.

      Delete
  11. Hi, thank you but I couldn't find the two files in my Alfresco:

    - share-workflow-form-config.xml
    - bootstrap-context.xml

    I'm using Alfresco Community Edition 5.1 under Windows 8

    Can I add those two files to My Alfresco ? If so, where can I find them ?

    ReplyDelete