Including Custom Features in a Workflow
This topic describes how to include custom features in a workflow.
Customizing the Task Distribution Strategy
The task distribution strategy is specified in the task response class. To implement a custom task distribution strategy, do the following:
-
Create a subclass of EnsLib.Workflow.TaskResponseOpens in a new tab and override its OnNewTask() callback method (and possibly other methods). The first subsection provides details on the options.
-
Make sure to invoke the custom task response class. This is discussed in the second subsection.
Creating a Custom Task Response Class
When you create a subclass of EnsLib.Workflow.TaskResponseOpens in a new tab, you override its OnNewTask() callback method (and possibly other methods). The following is a list of the callback methods that you can override:
-
OnAction() — Called when a user selects an action from the worklist form. Typically this marks the end of a task.
-
OnAssign() — Called when a user requests ownership of a task associated with it. Typically this method performs the assignment.
-
OnCancel() — Called when a task is cancelled, for example when it times out.
-
OnFormSubmit() — Called when the task form associated with this task is submitted.
-
OnNewTask() — Called when a new task is received by the Workflow Engine. Typically this method associates the task with members of the current role.
-
OnRelinquish() — Called when a user requests giving up ownership of a task associated with it. Typically this method unassigns the task and then sends the task back to others in the role.
-
OnRoleChange() — Called when a user or role definition associated with this task is changed, for example when the list of users within a role changes.
EnsLib.Workflow.TaskResponseOpens in a new tab callback methods control the distribution of tasks by calling a number of API methods defined in the Workflow Engine (EnsLib.Workflow.EngineOpens in a new tab).
The following is a list of the class methods in EnsLib.Workflow.EngineOpens in a new tab that you can use when you override the callbacks listed previously.
-
AssignTask() — Assign a task to a specific user.
-
CompleteTask() — Mark a task as Completed and return the response to the caller.
-
FindLeastBusyUser() — Return the name of the “least busy” user. This is the user with the fewest assigned tasks in the system.
-
SendTask() — Send a task to a specific user.
-
SendTaskToAll() — Send a task to all users in the current role.
-
SendTaskToTitle() — Send a task to one or more users with the given title in the current role.
-
SendTaskToTop() — Send a task to the top n users in the current role, according to their respective ranking in the role.
-
UnassignTask() — Remove task assignment.
For details on these methods, see the InterSystems Class Reference.
Invoking the Custom Task Response Class
A task request message has class parameter (RESPONSECLASSNAME) that specifies which response class to use. You can override this by setting the %TaskHandler property of the request class.
This means that you have two ways to cause the task request to use the desired task response:
-
Optionally create a subclass of EnsLib.Workflow.TaskRequestOpens in a new tab and override its RESPONSECLASSNAME parameter to equal the name of your custom task response class. For example:
Class MyApp.MyWorkflowRequest Extends EnsLib.Workflow.TaskRequest
{
Parameter RESPONSECLASSNAME = "MyApp.MyWorkflowResponse";
}
Then use this message class in the appropriate parts of the workflow process.
-
In the workflow process, when making the call to the workflow operation, set the value of the %TaskHandler property of the request instance so that it gives the name of the desired task response class name. For example:
set callrequest.%TaskHandler="MyApp.MyWorkflowResponse"