Custom workflow steps

You can extend the list of standard steps in the workflow designer tool by creating custom workflow steps. Custom workflow steps make it easy for workflow designers to drag, drop and configure a step into a workflow to call a SmartObject method.

To create a custom workflow step you must register the custom step by pointing it to a Service Method of a Service Object, and configuring the display values and icon for the custom step. Once the custom step is registered, it will appear in the K2 Workflow Designer and designers can use the custom step against a SmartObject that contains the Service Object method associated with the custom step.

For examples that demonstrate how to create custom workflow steps, see Example: Creating a custom workflow step and Example: Using JSSP and Custom Workflow steps together.

How custom workflow steps work

To understand how custom steps work, you first need to understand how SmartObjects work. For an overview of SmartObjects, see the topic SmartObject terminology and architecture and for an overview of Service Types see the topic Service Types in the User Guide. You should understand how Service Types, Service Objects and Service Object methods are related, and then how Service Instances and SmartObjects are related.

Essentially, when you register the custom step, you will tell K2 which Service Type, Service Object and Service Object method to use for the custom step. When a workflow designer uses your custom step in a workflow, they need to select the Service Instance of the targeted Service Type ("connection") to use when the workflow executes. Under the covers, K2 will find and execute the relevant SmartObject method in the specified Service Instance that matches the Service object method defined for the custom step.

Registering the custom workflow step

Using the custom workflow step in workflow designer

Service Object consistency

Because of the way that custom steps infer the SmartObject to call at runtime (based on the Service Type and Service Object method), custom steps are best suited when Service Instances of the Service Type exposes Service Objects with the same structure. In other words a Service Type with consistent Service Objects, where the Service Objects have the same properties and methods regardless of the service instance they are in, would work well. Something like the standard SQL Server Service Type may not work well, since the Service Objects in this service are different based on the SQL database targeted by different Service Instances of the Service Type. Consider limiting your custom steps to service types where the Service Objects are guaranteed to be consistent across Service Instances.

At runtime, the custom step definition compares the Service Instance information (the connection that the workflow designer selected when configuring the custom step) to the Service Type, Service Object, and Service Object Method that you chose when creating the custom step. It then executes the SmartObject that matches the definition of the custom step, using the following logic:

  1. If there is only one Service Object in the selected connection/Service Instance, use that Service Object even if the name does not match.
  2. If there is more than one Service Object in the selected connection/Service Instance, use the Service Object where the name matches.
  3. If there is more than one item in the collection, but no name matches, you will see a validation error: "A single, matching SmartObject was not found."
  4. If there are no SmartObjects in the selected connection/Service Instance, you will see an error like "a SmartObject was not found".

See Creating custom workflow step for more information about validation that happens when you drag a custom step onto the canvas.

See these topics to learn how to set up custom workflow steps:

Considerations