I'm required to build a workflow that allows the admin to select two assignees from two different groups in the first task of the workflow. Can I use two assignee controls in one form ? How?
Asked
Active
Viewed 930 times
1 Answers
5
You need to:
In the task content model, define the 2 assignees as 2 seperate associations of your task type.
<type name="my:starttask"> <parent>bpm:startTask</parent> <associations> <association name="my:firstassignee"> <title>firstassignee</title> <source> <mandatory>false</mandatory> <many>false</many> </source> <target> <class>cm:person</class> <mandatory>false</mandatory> <many>false</many> </target> </association> <association name="my:secondassignee"> <title>secondassignee</title> <source> <mandatory>false</mandatory> <many>false</many> </source> <target> <class>cm:person</class> <mandatory>false</mandatory> <many>false</many> </target> </association> </associations> </type>
In your share config custom, define the 2 associations as authority controls:
<config condition="activiti$myworkflow" evaluator="string-compare"> <forms> <form> <field-visibility> <show id="my:firstassignee" /> <show id="my:secondassignee" /> </field-visibility> <appearance> <field set="actors" id="my:firstassignee" > <control template="/org/alfresco/components/form/controls/authority.ftl"> </control> </field> <field set="actors" id="my:secondassignee"> <control template="/org/alfresco/components/form/controls/authority.ftl"> </control> </field>
In your bpm20 file, define two ActivitiScriptNode vars in your process and an ExecutionListener to the usertask/starttask having the two cm:person associations. That execution listener should be taking the entered values and placing them into the process scoped variables like this:
<extensionElements> <activiti:taskListener class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener" event="complete"> <activiti:field name="script"> <activiti:string> execution.setVariable('firstActivitiScriptNodeVar', task.getVariable('my_firstassignee')); execution.setVariable('secondActivitiScriptNodeVar', task.getVariable('my_secondassignee')); </activiti:string> </activiti:field> </activiti:taskListener> </extensionElements>
Then add this code to the UserTasks you which to assign to the entered users like this:
<humanPerformer> <resourceAssignmentExpression> <formalExpression>${firstActivitiScriptNodeVar.properties.userName}</formalExpression> </resourceAssignmentExpression> </humanPerformer>

Younes Regaieg
- 4,156
- 2
- 21
- 37

Stefan De Laet
- 1,409
- 11
- 20
-
thanks alot !! but how can I assign the use to appropriate process variables ? I'm trying to use an executionlistener inside the start event with the event property set to end but it's not working – Basil Jan 07 '16 at 13:06
-
@yreg excuse me but I'm new to alfresco, how are the ActivitiScriptNode vars defined? are they the regular vars inside the execution listener ?? – Basil Jan 07 '16 at 16:59
-
@basil I updated the post with code snippet for exporting task local vars to the current execution – Younes Regaieg Jan 07 '16 at 17:26
-
@YReg when I use the
tag to assign the tasks to users in vars the workflow fails to start with no output other than stating that it's a WorkflowException, any suggestions? – Basil Jan 10 '16 at 06:42 -
Can you provide a paste with your full workflow / or at least the part of it related to this question ? you can use pastebin.com for that – Younes Regaieg Jan 10 '16 at 10:18
-
here is a full paste, and thanks for you continuous help :) here is my workflow model http://pastebin.com/jX3W9CsQ and the related snippet of my workflow bpm file http://pastebin.com/LgWNsmnh – Basil Jan 10 '16 at 12:31