cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the owner of a task?

bbarani
Champ in-the-making
Champ in-the-making
Hi,

I have a simple workflow with custom form.

I figured out a way to set the owner of the task and it seems to work fine..

public class ArchiveTask implements org.activiti.engine.delegate.JavaDelegate

{
   public void execute(DelegateExecution execution) throws Exception {
      String assigneeName = (String) execution.getVariable("user");
      TaskService taskService = execution.getEngineServices()
            .getTaskService();
      List<Task> tasks = taskService.createTaskQuery()
            .taskAssignee(assigneeName).list();
      for (Task task : tasks) {
         task.setOwner(assigneeName);
      }

   }
}

Can someone let me know if I am right?


Thanks,
Barani
7 REPLIES 7

trademak
Star Contributor
Star Contributor
Hi,

Yes that works. You could also use the setOwner method of the TaskService.

Best regards,

sarkar92
Champ in-the-making
Champ in-the-making
Hi,

I have a simple workflow with custom form.

I figured out a way to set the owner of the task and it seems to work fine..

public class ArchiveTask implements org.activiti.engine.delegate.JavaDelegate

{
public void execute(DelegateExecution execution) throws Exception {
  String assigneeName = (String) execution.getVariable("user");
  TaskService taskService = execution.getEngineServices()
    .getTaskService();
  List<Task> tasks = taskService.createTaskQuery()
    .taskAssignee(assigneeName).list();
  for (Task task : tasks) {
   task.setOwner(assigneeName);
  }

}
}

Can someone let me know if I am right?


Thanks,
Barani


I also try the same code but get an error

I am using activiti 5.9

import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.task.Task;

import com.sysvana.provisioning.ProvisioningServices;
import com.sysvana.provisioning.ProvisioningServicesProxy;
import com.sysvana.request.Group;
import com.sysvana.request.RequestServices;
import com.sysvana.request.RequestServicesProxy;


public class CreateAssigneeList implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) throws Exception{

String groupJoinApproverEmail = "";

try{

String groupDN = (String)execution.getVariable("groupDN");
String screenName = (String)execution.getVariable("screenName");


TaskService taskService = execution.getEngineServices()
.getTaskService();
List<Task> tasks = taskService.createTaskQuery()
.taskAssignee(screenName).list();
for (Task task : tasks) {
task.setOwner(screenName);
}

it gives an error in the highlighted line….
is there anything wrog in my code??
please help

sarkar92
Champ in-the-making
Champ in-the-making
please help. I am using activiti 5.9

jbarrez
Star Contributor
Star Contributor
Activiti 5.9 does not have that method yet. You'd need to upgrade.

sarkar92
Champ in-the-making
Champ in-the-making
is there any other way I can set owner in activiti 5.9

trademak
Star Contributor
Star Contributor
You can retrieve the current process engine by ProcessEngines.getDefaultProcessEngine() in Activiti 5.9
Be aware though that this will create a new transaction.

Best regards,

jbarrez
Star Contributor
Star Contributor
It will create a new transaction and that means it doesnt see any of the data which hasn't been comitted yet.