Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a list of candidate users to an activiti workflow task in alfresco?

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?

like image 737
Ian Williams Avatar asked Nov 25 '12 18:11

Ian Williams


1 Answers

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.

like image 190
Ian Williams Avatar answered Sep 26 '22 08:09

Ian Williams