Dispatch action event

Rule types – Abstract

Purpose: Triggers a Custom action event with a defined data object as data context, which is processed completely before the surrounding event handling continues.


images/download/attachments/177911385/image-2024-9-16_9-55-14-version-1-modificationdate-1726473314176-api-v2.png

Trigger Event (action)

The Dispatch action event triggers a Custom action event and passes either the current reference object or an alternating reference object determined as the return value of a value solver as the 'input value'.

The impact of triggering an event depends on whether Event handling exist that consider triggering it. Often the 'Validating rule' of an event handler define specific requirements, e.g. a Check type, so that it only becomes active if a suitable 'input value' is passed.

Via the options (see 'Configuration' below for details), it is possible to control when the custom action event should be triggered at runtime (immediately or after the commit) and how event handlings are then executed (synchronous/serial or asynchronous/parallel).

In the data context of the triggered event, all variables present in the calling context are available in addition to the reference object defined when the event was triggered. However, these are not passed directly but 'cloned' beforehand. Therefore, the values of variables that are changed or created when processing the triggered event are not available afterwards in the context of the calling event handler. Therefore, they cannot be used to provide 'feedback' for the calling event handler. Where this is required, the 'feedback' must be via the reference object provided by the calling event handler. If necessary, an entity generated by Create instance ('Client object') or Create list can also be used as a reference object, to which suitable 'return values' can be assigned.

Configuration

The Event parameter supports the static selection for exactly one Custom action event based on the associated dynamic enumeration via a Combobox with a search function (see screenshot on the right).

NOTE◄ The selection options are limited via Dynamic enum filters if these are applicable in the context of the configuration. An existing selection does not have to be included in the selection list. It can be kept, changed or removed, but is not selectable again after removal.

images/download/attachments/177911385/image-2024-9-16_9-56-48-version-1-modificationdate-1726473407477-api-v2.png

The Entity parameter determines the 'input value' that will be passed to the event identified by Event:

  • If no value resolver is defined for the Entity, the current reference object from the context of the Dispatch action event action is passed to the event at runtime.

  • If a value resolver is configured, its return value (possibly also 'no value', i.e. null) is passed to the event at runtime. In the example on the right, only the address (address) of the reference object of the 'User' type is passed as an input value to a Custom action event ('Check address').

images/download/attachments/177911385/image-2024-9-16_9-58-8-version-1-modificationdate-1726473488356-api-v2.png

The Dispatch action event event action provides two options that control when and how a Custom action event is triggered:

  1. The option Dispatch after commit with a new Transaction can be set if the event should not be executed within the current transaction and immediately, but only (and only) when it is successfully completed ('Commit').

  2. When a Dispatch after commit with a new Transaction event is triggered, the exact sequence depends on the Dispatch async option:

    1. If the Dispatch async option is not checked (default), the event will be triggered after the commit, but it will still be executed synchronously. Then the triggered event handlers are assigned to the same thread on the server CPU that handles the dispatched event handler. The dispatched event handling is considered effectively finished only when the handling of all events synchronously triggered after the commit is completed. If this concerns several events, they are processed by the thread 'serially', i.e. strictly one after the other according to the order in which they were dispatched.

    2. If the option Dispatch async is checked, then the respective event handling can be executed asynchronously and assigned to the next available thread from the thread pool of the server CPU. If the event can be assigned to another thread, the dispatching event handler immediately addresses the next event, if any, in the 'queue' for triggering after the commit. This is then immediately started in parallel with the asynchronously dispatched predecessor and processed either synchronously or asynchronously again.

NOTE◄ The Dispatch async option affects the event processing flow in a similar way as the 'Synchronous' option affects the profile call during Export (only with a different polarity of the off/on selection).

Since the Dispatch async option is only selectable in conjunction with the Dispatch after commit with a new Transaction option, three use cases can be configured:

When to trigger? ►

How to trigger? ▼

Trigger immediately

Trigger after commit with a new transaction

Trigger
synchronously

images/download/attachments/177911385/image2021-10-20_15-17-16-version-1-modificationdate-1726470893699-api-v2.png

The event is dispatched immediately and synchronously and 'handled' before any subsequent event actions.

images/download/attachments/177911385/image-2024-9-16_9-58-26-version-1-modificationdate-1726473505506-api-v2.png

images/download/attachments/177911385/image2021-10-20_15-17-30-version-1-modificationdate-1726470893696-api-v2.png

The event is dispatched after the commit and synchronization. Event handlers use the same thread as the triggering event handler. Multiple synchronously dispatched events are processed serially.
images/download/attachments/177911385/image-2024-9-16_9-58-56-version-1-modificationdate-1726473536181-api-v2.png

Trigger
asynchronously

(Dispatch async is not applicable 'before the commit')


images/download/attachments/177911385/image2021-10-20_15-18-7-version-1-modificationdate-1726470893674-api-v2.png

The event is dispatched after the commit and asynchronization. It is assigned to the next available thread. Any subsequent events can therefore be processed in parallel.

images/download/attachments/177911385/image-2024-9-16_9-59-33-version-1-modificationdate-1726473572529-api-v2.png

NOTE◄ With the Dispatch async option, all variables are passed on as a copy in order to prevent parallel accesses to any objects contained therein.

Example

Simple example

In the course of an interactive action for an existing shipment (e.g. assigning the working state 'permissions'), the responsible user should be informed in a compact form about the 'participants' specified in company and address attributes for the shipment in question. Here, the Company type should appear as the title and a concatenation of selected address attributes in a standalone notification for each relevant attribute.

Example:

images/download/attachments/177911385/image2021-2-10_18-43-46-version-1-modificationdate-1726470893806-api-v2.png

Configuration:

So that the display of address attributes in the desired format can also be used in other contexts, a Custom action event with the name 'Info: Address' is defined. This event can be triggered whenever a user is to be notified about the content of a certain 'Company and address attribute'.

For our example, we will create an event handler that is triggered when a shipment is assigned the 'Permissions' working state.

The Actions on passed rule are configured as shown on the right:

  • A For each loop event action iterates over the entries returned by the Attribute (Resolvers) for the 'Company and address attribute' attribute type.

  • Within the loop and via all 'Company and address attributes' of the shipment, the Dispatch action event event action is executed.

  • 'Check address' is selected as the Event, to which the event handling presented below should react.

  • Since no value resolver is configured for the Entity, the reference object valid within the loop, i.e. the respective company and address attribute, is passed to the event as 'input value'.

images/download/attachments/177911385/image-2024-9-16_10-3-48-version-1-modificationdate-1726473828269-api-v2.png

For the output of the notification in response to the 'Info: Address' event, the following event handling is configured:

  • The custom action event 'Info: Address' defined for this purpose serves as the Triggering event.


  • The Validating rule collapsed in the image contains a Check type for the type 'Company and address attribute', so that a notification is only issued if the 'input value' of the event corresponds to this type. Since this type is uniformly applicable for company and address attributes of all business objects, the event handling can also be used for address attributes of other business object types (order, manifest, etc.).


  • A Show alert (Popup) event action with the Type 'Info' (see image above) should be executed as the Action on passed rule.


  • In the Title content builder, a Value from localization value resolver procures the localization for the Company type, which can be read in the 'Type' (companyType) field of the company and address attribute (not expanded in the image).


  • The Message content builder uses a Concat strings value resolver to create a text formatted with inserted literals from some components of the address. Specifically, the address fields 'name 1' (address.name1), the 'city' (address.city) and the Country in the 'country code' field (address.countryCode) are used here.

    NOTE◄ Since only the internal name of the respective entry is to appear in the dynamic enumeration Country for the 'country code', here – in contrast to the access to the Company type in the Title content builder – no Value from localization value resolver is used to return the respective localized full text for the country in the current language of the session.

images/download/attachments/177911385/image-2024-9-16_11-1-44-version-1-modificationdate-1726477303551-api-v2.png

NOTE◄ The Event recorder makes it possible to trace which Input value was used to call a Custom action event and when:

images/download/attachments/177911385/image2021-2-10_18-50-55-version-1-modificationdate-1726470893816-api-v2.png

  • Similarly to the example shown at the beginning, three address attributes were found in a shipment and passed on to the custom action event 'Info: Address' for the purpose of 'Notification'.

  • The Input value tab in the detail area shows the entity of the last call with the Company type 'Loading party' (DPA).