8

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?

Ian Williams
  • 141
  • 1
  • 1
  • 7
  • Is my answer working for you? – Tahir Malik Nov 29 '12 at 12:26
  • Similar to the latest answer from user68910801 you can also create a list in Rhino-based JavaScript (used in Alfresco). It just is a bit more annoying to handle since a) you don't have the `Java.type()` operation (instead you use `Packages.java.util.ArrayList`), b) the JavaScript String type in Rhino does not map to Java String, and c) a list is implicitly handled like a array-like object and some of its methods (like add) may be hidden – Axel Faust Jun 22 '17 at 06:31

3 Answers3

5

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.

Ian Williams
  • 141
  • 1
  • 1
  • 7
1

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.

Tahir Malik
  • 6,623
  • 15
  • 22
  • It has taken me a long time to minimally understand the workflows. I believe the activiti:candidateUsers expression that Activiti Designer created for me is a activiti extension which simplifies the potentialOwner method. Passing the string ${ipw_reviwers} as the formal expression did not work for me, but your answer did at least unlock the old grey cells and move me forward. – Ian Williams Dec 02 '12 at 13:13
  • Glad that you found the real answer for your problem. – Tahir Malik Dec 03 '12 at 14:04
1

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);
  • 2
    Note that with Alfresco + Activiti embedded, whenever you use the class `org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate` you are using the Rhino script engine that is shipped with Alfresco. You usually never use the Nashorn engine in the Alfresco use case as long as you use the Alfresco-provided classes for the Activiti integration. Only when you use the default `` or `org.activiti.engine.impl.bpmn.listener.ScriptTaskListener` while running on JDK 8 will you use Nashorn. – Axel Faust Jun 22 '17 at 06:22