Cora Knowledge Center

Support

Fetch a Task

Use the API to fetch a task.

public virtual void FetchTaskInstance(int activityInstanceId, int userId)
        {
            IWorkflowExecutionService exe = WorkflowRuntime.Engine.GetServiceWithCheck<IWorkflowExecutionService>();
            ActivityInstance activityInstance = exe.GetActivityInstance(activityInstanceId);
            if (activityInstance.FetchedById.HasValue && activityInstance.FetchedById.Value > 0)
            {
                return;
            }
 
 
            TaskInstance taskInstance = activityInstance.MessagesInstances.FirstOrDefault(
                t => t.ToId == userId) as TaskInstance;
 
            if (taskInstance == null)
            {
                return;
            }
 
            TaskExecutor taskExecutor = new TaskExecutor(taskInstance);
            taskExecutor.Fetch();
        }