Basic Concepts
Some basic concepts are presented here, for your clear understanding of how Workflow Studio works and its main components.
Workflows and Tasks
Workflow Studio works with two major concepts: workflows and tasks.
A workflow is a representation of a business process. In Worklow Studio, the workflow concept is split in two more specific concepts: workflow definition, which is the specification of a business process, and workflow instance, which is a running business process.
A task is a pending work for a user. In Workflow Studio, the task concept is split in two more specific concepts: task definition, which is the specification of a task, and task instance, which is actually a existing pending task for a user.
Workflow Definition
A workflow definition is the representation of a business process. For easy understanding, we can compare the workflow definition to a flowchart which specifies how the business process work.
In a workflow definition you specify which actions are to be performed (update database, send e-mail, run a script and, more important, create a task), and in which order. If you are creating a workflow definition for order processing, for example, then you might want to check if the order amount is higher than 10 000. If not, then create an approval task for the local manager. If yes, create an approval task for the director. In any case of approval, send an e-mail for the financial department.
You can use the workflow designer to visually build the flowchart for the workflow definition. All the workflow definitions are kept in the database. Each workflow definition receives a name that uniquely identifies it (for example, "order processing", "software deployment", "help desk support", etc.).
Workflow Instance
A workflow instance is a running instance of a workflow definition. A single workflow definition will generate an unlimited number of workflow instances.
For example, you can have a single workflow definition for order processing, and for each order, you will have a workflow instance. In a workflow definition you might have a variable named "Order number". Each workflow instance will have its own order number, and the variable "Order number" will have a different value. Each workflow instance will have its own state and internal variable values.
A workflow instance can be started, running or finished. All workflow instance records are kept in the database, even the finished ones.
Task Definition
A task definition specifies a task to be created for a user. It's not the task itself, but a specification for the task.
In the task definition you specify the subject, task name, description, the user, a list of valid status, and other properties. A task definition is always "inside" a workflow definition. One of the actions you can define in a workflow definition is generating tasks, and the task definition is part of the action specification.
For example, in a workflow definition for order processing, you might want to create a task for the manager to approve the order. In this case, the task definition would be something like this:
Subject: Order approval
Description: Please approve the order [OrderNo]
User: Manager
Valid Status: Waiting approval, approved, rejected
Task Instance
A task instance is a task created for an user based on a task definition. A single task definition can generate several task instances.
A task instance is created when a workflow instance is run and reaches to a point where a task must be created, based on a task definition. At that time, the task instance is created for a specified user.
Each user has a list of his/her pending task instances. Once the task is finished it is removed from the list of pending tasks. There is still an option for listing the closed tasks, in the task list window.
Each task instance has its own record in the database. Even if the task is closed, the record is not deleted.
Workflow Engine
The workflow engine is the place where the workflow instances are run. It creates the instance, runs it, and terminates it when the workflow instance is finished. The workflow engine can run various instances at the same time.
In current version, the workflow engine is just an internal thread-based class that creates a thread for each running workflow instance, and manages those threads.
Workflow Users and Groups
Workflow Studio is strongly based on tasks, which in turn are always assigned to an user or a group of users. So, Workflow Studio does also need to use information about users and groups.
Workflow Studio does not provide a full user control system, it does not have login dialogs, add/remove user, group definition interfaces, etc.. You must build the user management available in your application, or use a 3rd party tool to do that, like TMS Security System.
However, Workflow Studio needs to know about users and groups. So, you must fill in a list of valid users and groups, that will be used by Workflow Studio. This can be done at the beginning of the program.
The code below is an example that shows how to add users and groups to Workflow Studio.
// Add users and groups
with WorkflowStudio.UserManager do
begin
// Add all users
Users.Clear;
Users.Add('1', 'John', 'john@domain');
Users.Add('2', 'Sarah', 'sarah@domain');
Users.Add('3', 'Scott', 'scott@domain');
Users.Add('4', 'Mario', 'mario@domain');
Users.Add('5', 'Tina', 'tina@domain');
// Add groups and specify which users belong to each group
Groups.Clear;
with Groups.Add('managers') do
begin
UserIds.Add('1'); //John
UserIds.Add('2'); //Sarah
end;
with Groups.Add('programmers') do
begin
UserIds.Add('3'); //Scott
UserIds.Add('4'); //Mario
UserIds.Add('5'); //Tina
end;
end;
Note that two groups were created, and each group contains a list of user id's that belong to that group. Workflow Studio uses the user information to assign tasks, send e-mails, and other user-based tasks.
Version Control
It's possible that two different users load the same task or workflow instance, modify it, and try to save it. This could cause one user overwrite the changes made by the other user. It could happen either in your application code (manipulating tasks and instances from code) or when two users have their task lists dialogs open, for example.
To prevent this from happening you can set TWorkflowStudio.VersionControlEnabled property to true:
WorkflowStudio1.VersionControlEnabled := true;
This will force version control, which means if a user tries to update a task or workflow instance that is outdated (another user modified it since it was loaded from the database), an error will be raised and the update will not be performed.
This feature requires extra fields to be added to existing workflow database structure, be sure to run the proper SQL scripts to create those fields.