-->

How do I pass a list of candidate users to an acti

2019-04-23 12:52发布

问题:

I would like to be able to pass a list of users as candidates for a task. The users are retrieved from a data list and not available as a group. Activiti:candidateUsers would appear to be the right approach.

Assuming that the users have been obtained and set in the variable, ipw_reviwers.

<serviceTask id="alfrescoScripttask1" name="Alfresco Script Task" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
  <extensionElements>
    <activiti:field name="script">
      <activiti:string>logger.log("IPW - setup task");
      execution.setVariable('ipw_reviwers', "tom, dick, harry");</activiti:string>
    </activiti:field>
  </extensionElements>
</serviceTask>

The following to uses the variable ipw_reviewers

<userTask id="adhocTask" name="Adhoc Task" activiti:candidateUsers="${ipw_reviewers}" activiti:formKey="wf:activitiReviewTask">
  <extensionElements>
    <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
        <activiti:string>logger.log("IPW - create task");
        if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);
                  if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;</activiti:string>
      </activiti:field>
    </activiti:taskListener>
  </extensionElements>
</userTask>

No one is able to see or claim the task. If there is only one user in the list, that user is able to claim the task.

If activiti:candidateUsers is declared as

activiti:candidateUsers="tom, dick, harry"

then all three users are able to claim the task.

Can a list of users be passed to activiti:candidateUsers in a variable or should a different approach be used?

回答1:

Having confirmed that the problem existed activiti 5.10 from http://activiti.org and then trawled through the source of activiti from the git repo, I searched the activiti forums. I came across When you want to have multiple candidate users you'll have to use a Collection<String> variable on this forum http://forums.activiti.org/en/viewtopic.php?f=6&t=3635&p=14187&hilit=candidateuser#p14187.

I don't know how to execution.setVariable a Collection<String> from javascript (any answers?) but using groovy

List<String> users = [ 'tom', 'dick', 'harry'] as String[];
execution.setVariable('ipw_reviewers', users);

allows this task

<userTask id="mytask" name="My Task" activiti:candidateUsers="${ipw_reviewers}">
</userTask>

to work as desired.

For the time being in Alfresco, I have used used javascript to find the list of users from the data lists and placed them in a comma delimited string in one task and followed it with a script task in groovy that converts the string to a List<String> ready for use in the following tasks.



回答2:

If you take a look at the default workflows within Alfresco, like review-pooled.bpmn20.xml, then you'll see that it's using the potentialOwner element.

A snippet from the workflow:

<potentialOwner>
    <resourceAssignmentExpression>
    <formalExpression>${bpm_groupAssignee.properties.authorityName}</formalExpression>
    </resourceAssignmentExpression>
</potentialOwner>

So it's using the bpm_groupAssignee aspect to initiate this.

<!--  Submit review to multiple people (as included in a group) -->
      <type name="wf:submitGroupReviewTask">
         <parent></parent>
         <mandatory-aspects>
            <aspect>bpm:groupAssignee</aspect>
         </mandatory-aspects>
      </type>

In your case you could easily modify the <formalExpression> tag to your needs.



回答3:

In Nashorn (JDK8) java script engine, for defining list and setting it as a variable, following script of script task works:

var ArrayList = Java.type('java.util.ArrayList');
var list = new ArrayList();
list.add('a');
list.add('b');
list.add('c');
execution.setVariable('list', list);