The Workflow Viewtool, or just $workflowtool
, is a Velocity Viewtool used to perform workflow actions on content in the system — whether saving, publishing, archiving, or any of a variety of other operations.
Taken together, this and the $dotcontent
Viewtool allow the full suite of CRUD operations on content: $dotcontent
for reading, and $workflowtool
for creating, updating, or deleting.
Methods
The viewtool's many methods are outlined below.
Method | Return Type | Description |
---|---|---|
fire(properties, wfActionId) | Contentlet | Executes specified workflow on specified content map. Returns an object representing the contentlet processed by the workflow. |
findTaskByContentlet(contentlet) | List of workflow tasks | Fetches a workflow task object associated with contentlet. |
findTaskById(taskId) | Workflow task | Fetches a task directly by identifier. |
findWorkFlowComments(task) | List of workflow comments | Fetches workflow comments. |
findWorkflowHistory(task) | List of workflow history entries | Fetches the entire history of a workflow task. |
findStep(stepId) | Workflow step | Fetches a workflow step. |
findSteps(scheme) | List of workflow steps | Fetches all steps associated with a workflow scheme. |
findStepsByContentlet(contentlet) | List of workflow steps | Fetches all workflow steps associated with a contentlet. |
findScheme(schemeId) | Workflow scheme | Fetches a scheme by identifier. |
findSchemes(showArchived) | List of workflow schemes | Fetches all workflow schemes, optionally including archived schemes. |
findSchemesForStruct(struct) | List of workflow schemes | Fetches workflow schemes associated with a content type. |
findAction(id, user) | Workflow action | Fetches a workflow action. |
findActions(step[s], user[, permissionable]) | List of workflow action | Fetches all actions associated with the supplied workflow step(s), with optional filtering options. |
findActionClass(actionClassId) | Workflow action class | Fetches an action class, or a mapping of actionlet to action. |
findActionClasses(action) | List of action classes | Fetches all action classes of an action. |
findParamsForActionClass(actionClass) | List of actionlet parameters | Fetches all special parameters used by an actionlet/action class. |
findActionlet(clazz) | Workflow actionlet | Returns a single workflow sub-action by class. |
findActionlets() | List of actionlets | Returns all workflow sub-actions. |
Fire
This is a versatile, bread-and-butter method that can fire any applicable workflow on any content map object, and returns the contentlet that results from workflow completion.
To successfully fire, this map must include, at minimum:
- A
contentType
property set to the content type's Velocity variable - Valid values for each of that content type's required fields, which may include title, host, etc.
Argument | Type | Details |
---|---|---|
properties | Content Map Object | A map of properties that represent all or part of a content item. |
wfActionId | String | The identifier of the workflow action to be executed. |
Basic example:
## $workflowtool.fire(Map properties, String wfActionId)
$workflowtool.fire($contentlet, "b9d89c80-3d88-4311-8365-187323c96436")
Creating a contentlet:
## Create map with a content type property
#set($newcon = {})
#set($dummy = $newcon.put("contentType", "Asdf"))
## Execute workflow with System Workflow Publish action ID
$workflowtool.fire($newcon, "b9d89c80-3d88-4311-8365-187323c96436")
Copying a contentlet (using Demo site Blog content):
## Get contentlet
#set($contentlet = $dotcontent.find("e7ceee89-3cc5-4e35-9795-5927ac88ad89"))
## Get user
#set($user = $cmsuser.getLoggedInUser())
## Find ID of Save and Publish workflow action
#set($actions = $workflowtool.findAvailableActions($contentlet.contentObject, $user))
#foreach($a in $actions)
#if($a.name == "Save and Publish")
#set($doact = $a)
#end
#end
## Create new content map
#set($newcon = {})
## Iterate over a contentlet to be copied to
## change the unique URL title, omit identifiers that would cause overwrite
#foreach($a in $contentlet.contentObject.map.keySet())
#if($a == "urlTitle")
#set($dummy = $newcon.put($a, "${contentlet.contentObject.map[$a]}1"))
#elseif($a != "identifier" && $a != "inode" && $a != "stInode")
#set($dummy = $newcon.put($a, "${contentlet.contentObject.map[$a]}"))
#end
#end
## Add content type and other required fields of this content type
#set($dummy = $newcon.put("contentType", "Blog"))
## Execute workflow
$workflowtool.fire($newcon, $doact.id)
Find Task by Contentlet
When passed a contentlet object, this method returns a corresponding workflow task object.
Read about the full schema of workflow task objects.
Basic example:
## $workflowtool.findTaskByContentlet(Contentlet contentlet)
#set($contentlet = $dotcontent.find("498276def5e54ff9194ffac6bf12a8ce").contentObject)
$workflowtool.findTaskByContentlet($contentlet)
Find Task by Identifier
When passed a workflow task identifier, this method returns the corresponding workflow task object.
Read about the full schema of workflow task objects.
Basic example:
## $workflowtool.findTaskById(String taskId)
$workflowtool.findTaskById("919cd65a-bfb9-4f59-97e9-ccb793a48b40")
Find Workflow Comments
This method takes a workflow task object and returns the list of comments associated with said task.
Basic example:
## $workflowtool.findWorkFlowComments(WorkflowTask task)
#set($task = $workflowtool.findTaskById("919cd65a-bfb9-4f59-97e9-ccb793a48b40"))
$workflowtool.findWorkFlowComments($task)
Find Workflow History
This method takes a workflow task object and returns the list of history entries associated with said task.
Basic example:
## $workflowtool.findWorkflowHistory(WorkflowTask task)
#set($task = $workflowtool.findTaskById("919cd65a-bfb9-4f59-97e9-ccb793a48b40"))
$workflowtool.findWorkflowHistory($task)
Find Step
Takes a workflow step identifier, and returns the corresponding workflow step object.
Basic example:
## $workflowtool.findStep(String stepId)
$workflowtool.findStep("dc3c9cd0-8467-404b-bf95-cb7df3fbc293")
Find Steps
Takes a workflow scheme object as its argument, and returns a list of workflow step objects.
Pairs well with findScheme or findSchemes.
Basic example:
## $workflowtool.findSteps(WorkflowScheme scheme)
#set($firstLiveScheme = $workflowtool.findSchemes(false)[0])
$workflowtool.findSteps($firstLiveScheme)
Find Steps by Contentlet
If provided a contentlet object, this method retrieves a list of workflow step the contentlet occupies.
Basic example:
## $workflowtool.findStepsByContentlet(Contentlet contentlet)
#set($recentCon = $dotcontent.pull("*",1,"modDate desc")[0].contentObject)
$workflowtool.findStepsByContentlet($recentCon)
Find Scheme
If provided the identifier of a workflow scheme, this method returns that scheme as an object.
Basic example:
## $workflowtool.findScheme(String schemeId)
$workflowtool.findScheme("d61a59e1-a49c-46f2-a929-db2b4bfa88b2")
Find Schemes
Fetches all workflow scheme. This method accepts a boolean argument that determines whether or not it will include archived schemes in the list.
Basic example:
## $workflowtool.findSchemes(boolean showArchived);
$workflowtool.findSchemes(false);
Find Schemes for Struct
Returns a list of workflow scheme associated with a content type, such as by passing a content object's structure
property.
Basic example:
## $workflowtool.findSchemesForStruct(Structure struct)
#set($ct = $dotcontent.pull("*",1,"modDate desc")[0].structure)
$workflowtool.findSchemesForStruct($ct)
Find Action
Takes two arguments: a workflow action identifier, and a user authorized to fire said action. Returns a workflow action object.
Basic example:
## $workflowtool.findAction(String id, User user)
#set($user = $cmsuser.getLoggedInUser())
$workflowtool.findAction("ceca71a0-deee-4999-bd47-b01baa1bcfc8", $user)
Find Actions
The findActions()
method is overloaded, and can accept several argument patterns. The first argument is either a single workflow step or a list thereof; the second is a user object, and the optional third argument is a permissionable obect. The method returns all actions associated with the workflow step(s) that are further filtered according to the other two arguments.
Basic examples:
## $workflowtool.findActions(WorkflowStep step, User user)
#set($step = $workflowtool.findStep("dc3c9cd0-8467-404b-bf95-cb7df3fbc293"))
#set($user = $cmsuser.getLoggedInUser())
$workflowtool.findActions($step, $user)
## $workflowtool.findActions(WorkflowStep step, User user, Permissionable permissionable)
#set($step = $workflowtool.findStep("dc3c9cd0-8467-404b-bf95-cb7df3fbc293"))
#set($user = $cmsuser.getLoggedInUser())
#set($permissionable = $dotcontent.pull("*",1,"modDate desc")[0].structure.parentPermissionable)
$workflowtool.findActions($step, $user, $permissionable)
## $workflowtool.findActions(List<WorkflowStep> steps, User user)
#set($multistep = $workflowtool.findStepsByContentlet($dotcontent.pull("*",1,"modDate desc")[0].contentObject))
#set($user = $cmsuser.getLoggedInUser())
$workflowtool.findActions($multistep, $user)
## $workflowtool.findActions(List<WorkflowStep> steps, User user, Permissionable permissionable)
#set($multistep = $workflowtool.findStepsByContentlet($dotcontent.pull("*",1,"modDate desc")[0].contentObject))
#set($user = $cmsuser.getLoggedInUser())
#set($permissionable = $dotcontent.pull("*",1,"modDate desc")[0].structure.parentPermissionable)
$workflowtool.findActions($multistep, $user, $permissionable)
Find Action Class
Action classes can be thought of as mappings connecting actionlets (a.k.a. workflow sub-actions) to the workflow actions they comprise.
This method takes an action class identifier, and returns the corresponding action class object.
Basic example:
## $workflowtool.findActionClass(String actionClassId)
$workflowtool.findActionClass("52c05cfd-5544-4fe1-9fa4-4e9d95059909")
Find Action Classes
Takes a workflow action object as an argument, and returns all associated action classes.
Basic example:
## $workflowtool.findActionClasses(WorkflowAction action)
#set($user = $cmsuser.getLoggedInUser())
#set($act = $workflowtool.findAction("ceca71a0-deee-4999-bd47-b01baa1bcfc8", $user))
$workflowtool.findActionClasses($act, $user)
Find Parameters for Action Class
This method accepts an action class as an argument, and returns the parameters unique to that actionlet/action class. For example, the Send an Email actionlet uses parameters such as fromEmail
, toEmail
, cc
, etc., which would all be returned as keys along with their corresponding parameter objects.
Basic example:
## $workflowtool.findParamsForActionClass(WorkflowActionClass actionClass)
#set($ac = $workflowtool.findActionClass("e17d08de-2b85-41aa-ae25-06ed3fa576dc"))
$workflowtool.findParamsForActionClass($ac)
Find Actionlet
This method takes an actionlet's “clazz” as a string argument. This is a common Java convention for a variable meant to refer to a class; think of it as class, but with a bit more zazz. The method returns the actionlet as an object.
Basic example:
## $workflowtool.findActionlet(String clazz)
$workflowtool.findActionlet("com.dotmarketing.portlets.workflows.actionlet.SaveContentAsDraftActionlet")
Find Actionlets
Returns a full list of actionlets. This method does not require an argument
Basic example:
## $workflowtool.findActionlets()
$workflowtool.findActionlets()