Listeners

It is possible to add listeners to almost every BPMN element. These listeners can execute custom logic when the element is in a certain state. Unlike Delegates, a listener is not visible on the BPMN diagram. It is hidden from the users. Some examples of elements to which you can add listeners:

  • take: A sequence flow is traversed.
  • create: A user task is created, meaning the task is initiated.
  • start: A service task starts its execution.

There are two different types of listeners:

  • execution listeners: A generic listener that you can add to almost every element, for example start events, service tasks, user tasks or sequence flows. API v1 execution listeners are part of the com.collibra.dgc.core.workflow.activiti.executionlistener Java Core API package.
  • task listeners: A listener you can only add to and that only works within a user task. API v1 execution listeners are part of the com.collibra.dgc.core.workflow.activiti.tasklistener Java Core API package.

API v2 listeners belong to the com.collibra.dgc.workflow.api.listener Java Workflow API package.

Deprecated Java Core API v1 listeners will not be available in the next major release. Use Java Workflow API v2 listeners where available or script tasks to replace the functionality of v1 listeners. See Alternatives to API v1 listeners for examples.

Similar to delegates, you can also construct your own listener on the fly that executes one single expression. However, it is not possible to have a return value.

This section describes the packaged listeners. Most listeners are used in the packaged workflows.

Alternatives to API v1 listeners

This section provides examples of alternatives to Java Core API v1 listeners.

ActionMailSender

API v1
com.collibra.dgc.core.workflow.activiti.tasklistener.ActionMailSender
API v2
com.collibra.dgc.workflow.api.listener.ActionMailSender

CheckMandatoryFieldCombinationTaskListener

API v1
com.collibra.dgc.core.workflow.activiti.tasklistener.CheckMandatoryFieldCombinationTaskListener
API v2
com.collibra.dgc.workflow.api.listener.CheckMandatoryFieldCombinationTaskListener

RunAsExecutionListener

Using this listener is erroneous and causes inconsistencies in the activity stream.
It is removed without providing a replacement.

RunAsReleaseExecutionListener

Using this listener is erroneous and causes inconsistencies in the activity stream.
It is removed without providing a replacement.

SendEscalationEventExecutionListener

API v1
com.collibra.dgc.core.workflow.activiti.executionlistener.SendEscalationEventExecutionListener
API v2
com.collibra.dgc.workflow.api.listener.SendEscalationEventExecutionListener

SetActivityStreamListener

API v1
com.collibra.dgc.core.workflow.activiti.listener.SetActivityStreamListener
API v2
com.collibra.dgc.workflow.api.listener.SetActivityStreamListener

SetFormSubtitleTaskListener

API v1
com.collibra.dgc.core.workflow.activiti.tasklistener.SetFormSubtitleTaskListener
API v2
com.collibra.dgc.workflow.api.listener.SetFormSubtitleTaskListener

SetMembersExecutionListener

API v1
com.collibra.dgc.core.workflow.activiti.executionlistener.SetMembersExecutionListener
API v2
com.collibra.dgc.workflow.api.listener.SetResponsibilitiesExecutionListener

SetRoleResourceTaskListener

API v1
<userTask id="userTask1" name="usertask1" activiti:candidateUsers="user(Admin), role(Normal), role(Business Steward), role(Community Manager)">
    <extensionElements>
        <activiti:taskListener event="create" class="com.collibra.dgc.core.workflow.activiti.tasklistener.SetRoleResourceTaskListener">
            <activiti:field name="resourceId" expression="${resourceIdToOverride}" />
            <activiti:field name="resourceType" expression="${resourceTypeToOverride}"></activiti:field>
        </activiti:taskListener>
    </extensionElements>
</userTask>
API v2
<scriptTask id="scripttask1" name="scripttask1" scriptFormat="groovy" activiti:autoStoreVariables="false">
    <script><![CDATA[
        execution.setVariableLocal("itemResourceIdCandidateOverride", ${resourceIdToOverride});
        execution.setVariableLocal("itemResourceTypeCandidateOverride", ${resourceTypeToOverride});
    ]]></script>
</scriptTask>

SetValueTaskListener

API v1
<userTask id="usertask1" name="usertask1" activiti:candidateUsers="role(Reviewer)">
<extensionElements>
    ...
    <activiti:taskListener event="create" class="com.collibra.dgc.core.workflow.activiti.tasklistener.SetValueTaskListener">
        <activiti:field name="resultVariable">
            <activiti:string>
		        <![CDATA[proposedUsers]]>
		    </activiti:string>
        </activiti:field>
        <activiti:field name="userExpression">
            <activiti:expression>
	            <![CDATA[${reviewerUserExpression}]]>
	        </activiti:expression>
        </activiti:field>
    </activiti:taskListener>
    ...
</extensionElements>
</userTask>

Add the following script as a step before usertask1.

API v2
<scriptTask id="scripttask1" name="Set reviewer as proposed users" scriptFormat="groovy" activiti:autoStoreVariables="false">
    <script><![CDATA[
        String userNames = users.getUserNamesCsv("${reviewerUserExpression}");
        execution.setVariableLocal("proposedUsers", userNames);
    ]]></script>
</scriptTask>

Overview task listeners

Deprecated Java Core API v1 listeners will not be available in the next major release. Use Java Workflow API v2 listeners where available or script tasks to replace the functionality of v1 listeners. See Alternatives to API v1 listeners for examples.

  • ActionMailSender: Sends workflow action emails for the task that this task listener is configured for. Only simple tasks are possible without required form input except buttons.
    Field nameMandatoryDescription
    templateNThe name of the template that should be used to generate the email.
    sectionNThe name of the section that should be used to generate the mail.
    grouped

    Y

    The option to send the action mail grouped or not, by default this option is false.

    subjectYThe subject of the action mail to be send for non-grouped email.
    executeIfTrueYThe option to send the action email (true) or not (false).

    includeActivityStream

    Y

    The option to include the activity stream in the email (true) or not (false)

    includeAttributes

    Y

    The option to include the attributes in the email (true) or not (false).

    includeRelations

    Y

    The option to include the relations in the email (true) or not (false).

    relationTypes

    only if includeRelations is true

    A comma separated list of relation types to be shown in the email.

    If the file is empty, all relation types corresponding to the matching assignment groups are displayed.

    attributeTypes

    only in includeAttributes is true

    A comma separated list of attribute types to be shown in the email.

    If the file is empty, all attribute types corresponding to the matching assignment groups are displayed.

  • CheckMandatoryFieldCombinationTaskListener: Checks if the configured combination of form property input fields have at least one value field filled in. If not a error message will be shown to the user.

    Field nameExpressionsMandatoryDescription
    formFieldsNYA CSV of form property ids to do the mandatory check on.
  • SetFormSubtitleTaskListener: This sets a given string value as the subtitle for the form to be displayed on the task. With this you can tweak the form presented to the user with custom subtitles.

    Field nameExpressionsMandatoryDescription
    subtitleYYThe string value for the form subtitle
  • SetRoleResourceTaskListener: This provides the possibility to override the business item that is used to determine the users with given roles scoped for a certain task. Useful when you want to evaluate candidate user expression against another resource than the current workflow business item. Keep in mind that this can make the candidate user check fail as it will only check on the current business item and will not take this listener into account. When using this listener disable the check on the workflow configuration page.

    Field nameExpressionsMandatoryDescription
    resourceIdYYThe id of the new resource
    resourceTypeYYThe String representation of the new resource type e.g. TE for term.
  • SetValueTaskListener: Sets a variable in the workflow context. It can be used to evaluate expressions or user expressions and store the parsed value in a task LOCAL variable. This means as soon as you exit the current user task, the variable will not be available anymore.

    Field nameExpressionsMandatoryDescription
    valuesExpressionY

    Y

    (if userExpression is not used)

    An expression that will be evaluated.
    userExpressionY

    Y

    (if valuesExpression is not used)

    User expressions that you want to have evaluated.
    resultVariableNYThe name of the variable for the result to be restored in

Overview execution listeners

Deprecated Java Core API v1 listeners will not be available in the next major release. Use Java Workflow API v2 listeners where available or script tasks to replace the functionality of v1 listeners. See Alternatives to API v1 listeners for examples.

  • FlushExecutionListener: This listener exists for a pure technical reason. When everything is executed in one transaction, data is not always flushed to the database in between. For example if you create assets in a workflow and right after that you want to add some relations, this will not work. The assets will not be detected by logic adding the relations and this will fail, unless you add this execution listener in between. For more information about transaction boundaries in a workflow please refer to the Flowable documentation and search for Transactions and Concurrency.
  • SendEscalationEventExecutionListener: Listener that triggers an escalation event. By default the escalation process is listening to these events to start it's execution. You can use this listener to trigger a escalation event yourself. It needs two input parameters:

    Field nameExpressionsMandatoryDescription
    taskIdNYThe ID of the task the escalation is for.
    escalationTypeNN

    The type of the escalation. This variable is used in the escalation process to determine which kind of escalation to execute.

    The default is mail so this is a optional parameter.

  • SetMembersExecutionListener: A listener to easily set members on the current workflow business item. It has three input fields:

    Field nameExpressionsMandatoryDescription
    userNamesYYA CSV of usernames you want to set a member for.
    roleNameYYThe name of the role. You can only specify one role to use at once.
    clearExistingNYIf true all existing members on the current business item will be deleted prior to adding new. If empty no clearing is performed.
  • SetActivityStreamListener: A listener capable of setting the filter which will be used to generate a activity stream. This listener is both a execution listener and a task listener. The filter it generates will be put in a local variable. This means, in the case of a usertask, the variable will only exist as long as the task exists. Outside of a user task, the variable will exist for the current execution only, meaning it will not be visible in super or sub process instances. You can decide for yourself if you want it to be used as a tasklistener or execution listener on user tasks.
    When the listener has been used, a user will be able to see a activity stream on the task bar. Also, when action mails are send, the configured activity stream can be included in the action mails for the current user task. There are a lot of configuration options which we will discuss next. Here is the list of all input fields. None of them are mandatory and if no input is provided, all changes since the start of the workflow on the current resource are listed.

    Field nameExpressionsMandatoryDescription
    userYNLimits to only show activities for the user with the given user name. Needs to be a username.
    roleYNFilter only the changes where the user, specified in the user parameter has a given role in. If no user is given, only the changes are returned performed by users having the given role.
    involvedUserYNOnly show activities where the given user is involved in/has a role in.
    involvedRoleYNFilter only the changes where the user, specified in the involvedUser parameters, has a given role in.
    startTimeEmptyNNThis will override the default: the start time is the beginning of the current workflow, meaning all activities since the beginning of time will be shown.
    startTaskNNThe task ID of the task to take as start timestamp to show activities for.
    startOnStatusChangeFromNNFill in the signifier of the status here if you want all activities to show since the latest status change from the given status.
    endTaskNNSets the end timestamp to the given task ID.
    resourceTypesNN Filter on the types to return the changes for. If empty or null, all resource types are taken into account.