Skip to main content
Version: Current

CreateTaskAsync

Definition​

Creates one or more tasks for designated participants by replicating an existing task from the specified task activity.

C#
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​

TaskCreateTaskResponse

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​

C#
public async Task CreateTasksForParticipants()
{
IControlRoomContext context = LoginControlRoom();
try
{
string processInstanceId = "70ad0ad4cb8642b6b08d650933fec950";
string taskActivityDisplayName = "CustomName";
var history = await context.ProcessInstances.GetActivitiesHistoryAsync(processInstanceId);
var activity = history.FirstOrDefault(item => item.Name == taskActivityDisplayName);
if (activity == null)
{
Console.WriteLine("No matching activity was found.");
return;
}

var participants = new List<TaskParticipant>
{
new TaskParticipant
{
ParticipantName = "demoUser",
IsGroup = false
},
new TaskParticipant
{
ParticipantName = "Test",
IsGroup = true
}
};
var response = await context.ProcessInstances.CreateTaskAsync(processInstanceId, activity.ActivityInstanceId, participants);
// Inspect the response for individual participant successes and failures.
}
finally
{
context.Close();
}
}
Connection helper
public IControlRoomContext LoginControlRoom()
{
string RequiredSetting(string name) => Environment.GetEnvironmentVariable(name) ?? throw new InvalidOperationException($"Set {name} before running this example.");
string serverUrl = RequiredSetting("INTELLIBUDDIES_SERVER_URL");
string userName = RequiredSetting("INTELLIBUDDIES_USERNAME");
string password = RequiredSetting("INTELLIBUDDIES_PASSWORD");
string connectionString = $"ServerUrl={serverUrl};UserName={userName};Password={password}";
IControlRoomContext context = new ControlRoomContext(connectionString);
context.Open();
return context;
}

See Get started for imports and connection settings.

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.