ECMA Scripts

The following objects are available (dependent on step type) within ECMA scripts:

MetaDataMaps

You can use workflow metadata to persist information that is required during the lifetime of the workflow. A common requirement of workflow steps is to persist data for future use in the workflow, or to retrieve the persisted data.

There are three types of MetaDataMap objects - for Workflow, WorkflowData and WorkItem objects. They all have the same intended purpose - to store metadata.

A WorkItem has its own MetaDataMap that can be only used while that workitem (e.g. step) is running.

Both Workflow and WorkflowData metadatamaps are shared over the entire workflow. For these cases it is recommended to only use the WorkflowData metadata map.

Creating Custom Workflow Step Components

Workflow step components can be created in the same manner as any other component.

To inherit from one of the (existing) base step components, add the following property to the cq:Component node:

  • Name: sling:resourceSuperType

  • Type: String

  • Value: One of the following paths that resolves to a base component:

    • cq/workflow/components/model/process
    • cq/workflow/components/model/participant
    • cq/workflow/components/model/dynamic_participant

Specifying the Default Title and Description for Step Instances

Use the following procedure to specify default values for the Title and Description fields on the Common tab.

NOTE
The field values appear on the step instance when both of the following requirements are satisfied:
  • The edit dialog of the step stores the title and description in the following locations: >

  • ./jcr:title

  • ./jcr:description locations

    This requirement is satisfied when the edit dialog uses the Common tab that the /libs/cq/flow/components/step/step component implements.

  • The step component or an ancestor of the component does not override the step.jsp script that the /libs/cq/flow/components/step/step component implements.

  1. Below the cq:Component node, add the following node:

    • Name: cq:editConfig
    • Type: cq:EditConfig
    NOTE
    For more information about the cq:editConfig node, see Configuring the Edit Behavior of a Component.
  2. Below the cq:EditConfig node, add the following node:

    • Name: cq:formParameters
    • Type: nt:unstructured
  3. Add String properties of the following names to the cq:formParameters node:

    • jcr:title: The value fills the Title field of the Common tab.
    • jcr:description: The value fills the Description field of the Common tab.

Saving Property Values in Workflow Metadata

NOTE
See Persisting and Accessing Data. In particular, for information about accessing the property value at runtime, see Accessing Dialog Property Values at Runtime.

The name property of cq:Widget items specifies the JCR node that stores the widget’s value. When widgets in the dialog of workflow step compnents store values below the ./metaData node, the value is added to the workflow MetaDataMap.

For example, a text field in a dialog is a cq:Widget node that has the following properties:

Name
Type
Value
xtype
String
textarea
name
String
./metaData/subject
fieldLabel
String
Email Subject

The value that is specified in this text field is added to the workflow instance’s [MetaDataMap](#metadatamaps) object, and is associated with the subject key.

NOTE
When the key is PROCESS_ARGS, the value is readily available in ECMA script implementations via the args variable. In this case, the value of the name property is ./metaData/PROCESS_ARGS.

Overriding the Step Implementation

Each base step component enable workflow model developers to configure the following key features at design time:

  • Process Step: The service or ECMA script to execute at runtime.
  • Participant Step: The ID of the user that is assigned the generated work item.
  • Dynamic Participant Step: The service or ECMA script that selects the ID of the user that is assigned the work item.

To focus the component for use in a specific workflow scenario, configure the key feature in the design and remove the ability for model developers to change it.

  1. Below the cq:component node, add the following node:

    • Name: cq:editConfig
    • Type: cq:EditConfig

    For more information about the cq:editConfig node, see Configuring the Edit Behaviour of a Component.

  2. Below the cq:EditConfig node, add the following node:

    • Name: cq:formParameters
    • Type: nt:unstructured
  3. Add a String property to the cq:formParameters node. The component super type determines the name of the property:

    • Process Step: PROCESS
    • Participant Step: PARTICIPANT
    • Dynamic Participant Step: DYNAMIC_PARTICIPANT
  4. Specify the value of the property:

    • PROCESS: The path to the ECMA script or the PID of the service that implements the step behavior.
    • PARTICIPANT: The ID of the user who is assigned the work item.
    • DYNAMIC_PARTICIPANT: The path to the ECMA script or the PID of the service that selects the user to assign the work item.
  5. To remove the ability of model developers to change your property values, override the dialog of the component super type.

Adding Forms and Dialogs to Participant Steps

Customize your participant step component to provide features that are found in the Form Participant Step and Dialog Participant Step components:

  • Present a form to the user when they open the generated work item.
  • Present a custom dialog to the user when they complete the generated work item.

Peform the following procedure on your new component (see Creating Custom Workflow Step Components):

  1. Below the cq:Component node, add the following node:

    • Name: cq:editConfig
    • Type: cq:EditConfig

    For more information about the cq:editConfig node, see Configuring the Edit Behavior of a Component.

  2. Below the cq:EditConfig node, add the following node:

    • Name: cq:formParameters
    • Type: nt:unstructured
  3. To present a form when the user opens the work item, add the following property to the cq:formParameters node:

    • Name: FORM_PATH
    • Type: String
    • Value: The path that resolves to the form
  4. To present a custom dialog when the user completes the work item, add the following property to the cq:formParameters node

    • Name: DIALOG_PATH
    • Type: String
    • Value: The path that resolves to the dialog

Configuring the Workflow Step Runtime Behavior

Below the cq:Component node, add a cq:EditConfig node. Below that add an nt:unstructured node (must be named cq:formParameters) and to that node add the following properties:

  • Name: PROCESS_AUTO_ADVANCE

    • Type: Boolean

    • Value:

      • when set to true the workflow will run that step and continue - this is default and also recommended
      • when false, the workflow will run and stop; this needs extra handling, so true is recommended
  • Name: DO_NOTIFY

    • Type: Boolean
    • Value: indicates whether email notifications should be sent for user participation steps (and assumes that the mail server is correctly configured)

Persisting and Accessing Data

Persisting Data for Subsequent Workflow Steps

You can use workflow metadata to persist information that is required during the lifetime of the workflow - and between steps. A common requirement of workflow steps is to persist data for future use, or to retrieve the persisted data from prior steps.

Workflow metadata is stored in a MetaDataMap object. The Java API provides the Workflow.getWorkflowData method to return a WorkflowData object that provides the appropriate MetaDataMap object. This WorkflowData MetaDataMap object is available to the OSGi service or ECMA script of a step component.