cancel
Showing results for 
Search instead for 
Did you mean: 

Multi Instance User task assignee overwriting

darkredd1
Champ in-the-making
Champ in-the-making
Good day All,

We are using the Activiti engine that came bundle with Alfresco 4.1*.
We have a custom workflow developed. In this workflow we have a review task that is a multi Instance, what happens is if any of the reviewer (starting from the second person) rejects, it goes back to the initiator. Once the initiator has made adjustments, they can send it back to the reviewer who rejected the document.

What we would like help with is the overwriting of the original assignees with reviewer who rejected and those ahead of them in the task; so if there are 4 Reviewers and the 3rd rejects. When the flow comes back, the userTask should be assigned to the 3rd reviewer followed by the 4th in the loop.

What we have tried was using the TaskService interface with no success, here is the implementation we tried with:

<blockcode>
package dac.gov.controller;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;

import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

public class RecommendationUser implements TaskListener
{
   @Override
   public void notify(DelegateTask execution)
   {
      // TODO Auto-generated method stub
      String user = execution.getVariable("sita_recommenders").toString();

      try
      {
         TaskService task = TaskService.class.newInstance();

         task.setAssignee(execution.getVariable("taskid").toString(), user);
         log.info("Reassigning");
      }
      catch (InstantiationException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (IllegalAccessException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
}
</blockcode>

If there is a way of achieving this please help.

Regards
DarkRedd
5 REPLIES 5

trademak
Star Contributor
Star Contributor
Hi,

<blockcode>
TaskService.class.newInstance()
</blockcode>

That's not how you should access the TaskService.
What you can do is the following:

<blockcode>
ProcessEngine processEngine = ProcessEngines.getProcessEngine(Context.getProcessEngineConfiguration().getProcessEngineName());
TaskService taskService = processEngine.getTaskService();
</blockcode>

Best regards,

darkredd1
Champ in-the-making
Champ in-the-making
Hi,

Thank you for the correction.

Though, it does not necessarily answer my question. My task is a multi Instance, with a collection of users involved, how would I then reassign the task with a new collection of users.
Here is the scenario I'm working on, there can 4 users in this task; say the first two approves the process and the third rejects. When the originator has done their part it has to be sent back to the user who rejected and then continue with the flow there onwards. Meaning the original collection of assignees has to be overwritten with a new one with on two users (the one who rejected the last one of the approves in line).

How do I achieve this?

Regards
DarkRedd

jbarrez
Star Contributor
Star Contributor
You would need to use variables for the assignments. When you arrive again in the multi instance, the variables will be used to set the assignee of the task (regardless of it is multi instance or not)

darkredd1
Champ in-the-making
Champ in-the-making
Hi Jbarrez,

I have tried your suggested solution to no success with the code:

<code>
var recommenders;

recommenders = dac_recommenders.get(current);

execution.setVariable('dac_recommenders', recommenders);
</code>

"current" represents the current user in the original collection. After setting this, I get a "Variable dac_recommenders' not a collection" when the task has to be created.
I don't know if I am the dumb one in that maybe I am failing to assign data to a collection variable.

The code above is run inside the "complete" event of a taskListener in a script.

Any other suggestions are welcome.

Thanks

jbarrez
Star Contributor
Star Contributor
This is code I wrote last week which kinde does what you want:

<code>
var feedbackProviders = new java.util.ArrayList();
feedbackProviders.add('gonzo');
feedbackProviders.add('mispiggy');
feedbackProviders.add('fozzie');
task.getExecution().setVariable('feedbackProviders', feedbackProviders);
</code>