CreateTaskAsync
Definition
Creates one or more tasks for designated participants by replicating an existing task from the specified task activity.
public Task<CreateTaskResponse> CreateTaskAsync(string processInstanceId, string activityInstanceId, IEnumerable<TaskParticipant> participants);
Parameters
processInstanceId String
The unique identifier of the process instance associated with the task activity.
activityInstanceId String
The unique identifier of the task activity to replicate for task creation.
participants IEnumerable<TaskParticipant>
A collection of participants for whom tasks will be created. Each participant can be an individual user or a group involved in the task.
Returns
A task representing the asynchronous operation. The result includes details about tasks that were successfully created, as well as information on any participants for whom task creation was unsuccessful.
Example
using IntelliBuddies.Client;
using IntelliBuddies.Client.Models;
namespace Example
{
public class Program
{
static async Task Main(string[] args)
{
string serverUrl = "http://demo.onintellibuddies.com";
string userName = "demo";
string password = "password";
using var context = new ControlRoomContext(serverUrl, AuthenticationType.Basic, userName, password);
context.Open();
string processInstanceId = "70ad0ad4cb8642b6b08d650933fec950";
// your task activity display name
string taskActivityDisplayName = "CustomName";
var activitiesHistory = await context.ProcessInstances.GetActivitiesHistoryAsync(processInstanceId);
// gets the task activity's info
var taskActivityHistory = activitiesHistory
.Where(ah => ah.Name == taskActivityDisplayName)
.FirstOrDefault();
if (taskActivityHistory != null)
{
var participants = new List<TaskParticipant>
{
new()
{
ParticipantName = "demoUser",
IsGroup = false
},
new()
{
ParticipantName = "Test",
IsGroup = true
}
};
var response = await context.ProcessInstances.CreateTaskAsync(processInstanceId, taskActivityHistory.ActivityInstanceId, participants);
}
}
}
}
Remarks
To get the activity instance id of the task activity, you can get the list of the current process instance's activity execution records and filter the records by the task activity's display name. You can use the activity instance id to create the tasks for the participants.
Suppose you provided one user participant and a group participant, and the group also contains the provided user. In this case, the API will create a task for the user participant, and the group user participant will be ignored.