Package com.smartgwt.client.docs

# Interface ReifyAddWorkflowTask

public interface ReifyAddWorkflowTask

### Adding Custom Workflow Tasks

You can define custom Workflow tasks and add them to the `com.smartgwt.client.tools.WorkflowEditor`. This applies whether you are using the Workflow Editor embedded in Reify or as a `standalone component` (see the @see Workflow Editor and @see Custom Task Editor samples). Custom tasks let designers cover additional use cases within the visual editor without writing code.

The overall steps are:

1. Create a `ProcessElement` subclass that performs the desired task.
2. Build a task editor so users can configure task properties (or skip this step for tasks with no configurable properties).
3. Register the task with the Workflow Editor via `WorkflowEditor.registerTaskDescriptor()` (or, in Reify, via `workflowTasks.xml`).

For Reify deployments, a `component schema` is also needed so the task can be serialized; see Task Schema (Reify) below.

Do I need a custom Workflow task?

Before building a custom task and editor, consider whether other approaches might work:

1. Custom services – if you are connecting to an enterprise web service, a custom DataSource may suffice; see `Adding Custom DataSources to Reify`. DataSources can model any network service, not just databases. For example, a proprietary messaging system with inputs like recipient, subject, message can be modelled as a DataSource where those are simply fields and sending is an "add" operation. A custom task may still be worthwhile if you want a specialized editing interface.

2. Actions on UI components – if your custom components support actions, you can expose them as setter methods (e.g. `setMode(newMode)`), add the setter to the Component Schema, and let designers invoke it via the built-in Set Properties workflow task.

Workflow Task

A new task must inherit from `ProcessElement` or a subclass like `ScriptTask` or `ComponentTask`, and override `ProcessElement.executeElement()` (or a subclass-specific method like `ScriptTask.execute()`). Return `true` for synchronous completion or `null` for asynchronous (then call `process.start()` when done).

Setting `ProcessElement.typeTitle` and `ProcessElement.classDescription` on the class provides default `title` and `description` values, so they don't need to be repeated in the `com.smartgwt.client.tools.WorkflowTaskDescriptor`.

For Reify, load the task implementation via `globalDependencies.xml` (see `"Adding Custom Components to Reify"`) or via `"Runtime Customization"`.

Task Schema (Reify)

In Reify, a `component schema` is needed so the task configuration can be serialized. The schema can be XML or JavaScript and requires:

- `ID` = same as your task class name
- `serverType` = "component"
- `inheritsFrom` = superclass name
- instanceConstructor = same as your task class name

For standalone WorkflowEditor usage without Reify, no schema is needed — tasks are serialized via `getProcessJS()` which uses JavaScript reflection.

Workflow Task Editor

A task editor lets users configure task properties. If a task has no configurable properties (e.g. a logout task), no editor is needed — simply omit the `editTask()` callback and `editorType`.

There are two approaches to building editors:

Approach 1: Subclass `com.smartgwt.client.tools.WorkflowTaskEditor` (or `com.smartgwt.client.tools.WorkflowComponentTaskEditor` for `ComponentTask`-based tasks). Override `getEditorComponents()`, `setEditorValuesFromDefaults()`, `getEditorValuesAsDefaults()`, and `validate()`. Set `editorType` on the task class to your editor class name. See the @see Custom Task Editor sample for a working example.

Approach 2: Provide an `editTask()` callback on the `com.smartgwt.client.tools.WorkflowTaskDescriptor`. This gives complete control — build any UI you like, then call `callback(editNode)` to save or `callback(null)` to cancel.

Several helper classes are available for building advanced property editors: `com.smartgwt.client.tools.WorkflowValuesBindingEditor`, `com.smartgwt.client.tools.WorkflowCriteriaBuilder`, `com.smartgwt.client.tools.WorkflowDynamicValueItem`, and `com.smartgwt.client.tools.WorkflowTemplatedTextItem`.

Registering the Task

For the `com.smartgwt.client.tools.WorkflowEditor` to show the new task in its task picker, register a `com.smartgwt.client.tools.WorkflowTaskDescriptor` via `WorkflowEditor.registerTaskDescriptor()`. To place the task under a custom folder, first call `WorkflowEditor.registerFolderDescriptor()` to create the folder, then set `taskPath` to the folder's `ID`. Descriptors can be removed at runtime via `WorkflowEditor.removeTaskDescriptor()`.

In Reify, the easiest approach is to add the descriptor to the default task tree in `[webroot]/tools/visualBuilder/ workflowTasks.xml`, which uses a tree structure similar to the tree XML loading example. The properties on each node are documented on `com.smartgwt.client.tools.WorkflowTaskDescriptor`.

A descriptor can also be registered at runtime via `Reify.registerWorkflowTaskDescriptor()`, which is useful for `"Runtime Customization"`.