Good day,
I am using the .net client Apis and trying to setAsignee after retrieving a task. how to do it ?
I am using the below code
public static void AssginTask(string userName, string processInstanceId)
{
var camunda = CamundaBootstrap.CreateCamundaInstance();//custom code returns instance of camunda client object
TaskQuery taskQuery = new TaskQuery { Active = true, ProcessInstanceId = processInstanceId };
var tasks = camunda.UserTasks.Query(taskQuery).List();
var userTasks = tasks.Result ;
foreach (var item in userTasks)
{
item.// set assignee here ??
}
}
Thank you
@a-mubarak You can’t do querying task and updating task via same api either via rest endpoint or external task clients. Querying & updating task in same request is possible if process engine is embedded. For embedded process engine you can try like this,
execution.getProcessEngineServices().getTaskService().createTaskQuery().active().singleResult().setAssignee("myself");
For setting assignee for atask via rest api, you need to make rest api call to set-assignee or update-task api.
(OR)
Suppose, if process engine is embedded, it will work as you mentioned it.
1 Like
@aravindhrs
Thanks you for your reply .
I managed to do it as the below code
using Camunda.Api.Client.ProcessDefinition;
using Camunda.Api.Client.ProcessInstance;
using Camunda.Api.Client.UserTask;
public static async Task AssginTaskAsync(string userName, string processInstanceId)
{
var camunda = CamundaBootstrap.CreateCamundaInstance();
TaskQuery taskQuery = new TaskQuery { Active = true, ProcessInstanceId = processInstanceId };
var tasks = camunda.UserTasks.Query(taskQuery).List();
var userTasks = tasks.Result ;
foreach (var item in userTasks)
{
//Assign tasks to user demos
await camunda.UserTasks[item.Id].SetAssignee(userName);
}
}
[TestMethod()]
public void AssginTaskAsyncTest()
{
new CamundaBootstrap("http://*******:8080/engine-rest", "demo", "demo");
var tasks = TransactionManager.AssginTaskAsync("demo", "407c4669-257c-11ea-8a19-000d3a8b17c2");
Assert.
}
Thank you,