Search code examples
alfrescoactivitibpmn

Assign a task to particular alfresco user based on value of variable/condition inside .bpmn2 file


Greetings to the community! I am using alfresco community edition 6.0.0 with the embedded activiti workflow engine. I have already created some users and I would like to create and deploy a .bpmn2 file which will describe the following workflow-scenario:

"Concerning the value of variable 'X', assign this task to this user".

The process of my bpmn2 file has currently this structure

<process isExecutable="true" id="example" name="example Activiti process">
    <startEvent id="start"
        activiti:formKey="wf:submitAdhocTask" />
    <sequenceFlow id='flow1' 
        sourceRef='start'
        targetRef='task1' />

    <userTask id="task1" name="The first task"
        activiti:formKey="wf:task1">
        <documentation> 
             The user assigned to this task will be decided according to the value of a variable
        </documentation>
       <extensionElements>
           <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
              <activiti:field name="script">
                 <activiti:string>

                 </activiti:string>
              </activiti:field>
           </activiti:taskListener>
       </extensionElements>
        <humanPerformer>
            <resourceAssignmentExpression>
                <formalExpression>${bpm_assignee.properties.userName}</formalExpression>
            </resourceAssignmentExpression>
        </humanPerformer>
    </userTask>

    <sequenceFlow id='flow3' sourceRef='task2'
        targetRef='theEnd' />

    <endEvent id="theEnd" />

I want to achieve the following scenario:

if(X < 5 ) { assign task1 to userA} else { assign task1 to userB}

My questions are the following:

1) Where to set this variable? I have created one using the workflow console:

var bpm:X*=5 

2) How to use the above variable in order to implement my scenario?

Any help would be greatly appreciated! thanks :)


Solution

  • I managed to solve this by adding the following to my activiti taskListener

     <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                      if (bpm_Y == 5 ) task.assignee = 'userA';
                      if (bpm_Y != 5)  task.assignee = 'userB';
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
    

    and passing the variable on the start process like 'start bpm:Y=10 '