You may customize Workflow Actions through a combination of Action properties, Workflow Subactions, and custom code.
There are three different ways you can add custom code to Workflow Actions:
|Velocity Script Subaction||Velocity||Executes the specified Velocity code (without displaying a popup) when a user executes the Action.|
|Custom Workflow Subaction Plugin||Java||Adds a custom Subaction to dotCMS. This Subaction can then be added to any Action just like the built-in Subactions provided by dotCMS.|
You may mix different methods and different types of code within the same Workflow Action. When mixing code it's important to understand that:
- Velocity and Java code are executed on the dotCMS server.
- When multiple code types are mixed, all server-side code is executed before all client-side code. This means, for example, that:
Action Property Sequence
Workflow Action properties and code are executed in the following order:
- Velocity code included in the Custom Code property.
- Subactions are executed in the order they are displayed in the Action.
- Any Subactions which execute code (such as the Velocity Script Subaction) are executed in the order of the Subactions.
- If any Subaction fail to execute, none of the Subactions following it will be executed.
This means, for example, that if you set any Velocity variables in the Custom Code field, the values of those variables will be available to Subactions that can access Velocity variables. However it also means that if you want any actions taken by the user in the Custom Code popup to change the results of any Subactions, you must use a method other than Velocity to modify those values (such as an AJAX call to execute a REST API method).
Example of Condition Based Workflow Action
The following is an example of a way to use the
$workflow.abortProcessor() to stop the workflow action from completing based on some condition in a Velocity Script Actionlet.
#if($content.getTitle().startsWith('wrong')) $dotlogger.info("Wrong") $workflow.abortProcessor() #else $dotlogger.info("OK") #end