Skip to main content

User Tasks

User Tasks allow you to manage tasks involving humans alongside standard computer tasks in your LittleHorse Workflow.

You can use the Workflow SDK's to schedule User Tasks, and also create lifecycle hooks such as:

  • Automatic Reassignment
  • Reminder Tasks
  • Automatic Cancellation.

See the Metadata Management docs for information about how to create a UserTaskDef.

Assigning User Tasks

You can assign a User Task in two ways:

  • To a specific User, specified by an arbitrary user id (and optionally a user group).
  • To a group of users.

Assigning to Users

To assign a user task to a specific user who is not a part of a group, you can use WorkflowThread#assignTaskToUser().

String hardCodedUserId = "some-user-id-or-email";
WfRunVariable userIdVariable = wf.addVariable("user-id", VariableType.STR);

// Hard-coded using a string
wf.assignUserTask("some-user-task-def", hardCodedUserId, null);

// Using a variable to set User Id
wf.assignUserTask("another-user-task-def", userIdVariable, null);

You can also assign a user task to a user as part of a group using WorkflowThread#assignUserTask:

WfRunVariable userIdVariable = wf.addVariable("user-id", VariableType.STR);
WfRunVariable userGroupVariable = wf.addVariable("user-group", VariableType.STR);
String hardCodedUserGroup = "finance";

// Hard-coded using a string
wf.asignUserTask("some-user-task-def", userIdVariable, hardCodedUserGroup);

// Using a variable to set User Group
wf.assignUserTask("another-user-task-def", userIdVariable, userGroupVariable);

Assigning to Groups

You can assign a task to a user group using WorkflowThread#assignUserTask().

String hardCodedUserGroup = "sales";
WfRunVariable userGroupVariable = wf.addVariable("user-group", VariableType.STR);

// Hard-coded using a string
String userId = null;
wf.assignUserTask("some-user-task-def", userId, hardCodedUserGroup);

// Using a variable to set User Group
wf.assignUserTask("another-user-task-def", userId, userGroupVariable);

Using User Task Outputs

The assignTaskToUser and assignTaskToUserGroup methods return a UserTaskOutput, which is a special type of NodeOutput. It can be used to:

  • Mutate variables
  • Schedule reminder tasks
  • Schedule user task reassignment.

Using the Form Output

You can use a UserTaskOutput to mutate variables. Note that a UserTaskDef has a series of fields, where each field has a name and value (which is a VariableValue containing a primitive type).

The UserTaskOutput is essentially a Json output where each key is the name of each field, and the value is the value typed by the user. Let's say I have a user task def with two fields:

  • userName, which is a STR
  • age, which is an INT

You can use the value as follows:

WfRunVariable age = wf.addVariable("age", VariableType.INT);
WfRunavariable userName = wf.addVariable("user-name", VariableType.STR);

UserTaskOutput formResults = wf.assignUserTask("my-user-task", "obi-wan", null);
wf.mutate(age, VariableMutationType.ASSIGN, formResults.jsonPath("$.age"));
wf.mutate(userName, VariableMutationType.ASSIGN, formResults.jsonPath("$.userName"));

Reminder Tasks

You can use the UserTaskOutput to schedule a "Reminder Task", which is a TaskRun that runs a set period of time after the User Task is scheduled. If the UserTaskRun has been completed, cancelled, or reassigned by the time the Reminder Task is scheduled, the Reminder Task does not execute.

UserTaskOutput userTask = wf.assignTaskToUser("some-task", "yoda");

int delaySeconds = 60; // wait one minute before reminder

String taskArg1 = "reply to my email, you must!";
String taskArg2 = "for my ally is the Force, and a powerful ally it is";

String taskDefName = "send-reminder";
wf.scheduleTaskAfter(userTask, delaySeconds, taskDefName, taskArg1, taskArg2);

Automatic Reassignment

You can use the UserTaskOutput to automatically "release" a task from a specific user to that user's group after a period of time passes.

note

This only works if you assign the user task to a user and specify the group the user belongs to.

String userGroup = "jedi-council";
UserTaskOutput userTask = wf.assignUsrTask("some-task", "Mace Windu", userGroup);

// If Mace Windu doesn't respond in 1 hour, allow any other Jedi Council member to claim
// the task.
wf.releaseToGroupOnDeadline(userTask, 60 * 60);