Parameters in event types

Event types can include parameters that application programs can read to customize how events are triggered.

As an example, consider an event type associated with the creation of “big” purchase orders. Naturally, the definition of what big is, varies for each installation.

An event type parameter can be defined to store that threshold. The program that triggers the event reads its value and fires the event or not.

Parameters in event types are not mandatory. They provide a common repository and an unified definition step for Event types and the values they depend on.

Parameters are stored as a varchar field, and our recommendation is to define a standard for each event type based on an SDT and provide an editor for that SDT in the module’s metadata. The editor is a web component that will be called by the module if necessary.

A default editor is included with the module, this editor works with values defined using the K2BAttributeValue SDT.

How to define parameters in an event type

To define parameters you must follow these steps:

Define how to store parameters.

This is entirely up to the developer, we recommend defining an SDT with the parameter values and storing the JSON serialization for that SDT. The module’s default editor was programmed to use the K2BAttributeValue SDT.

Define the parameters editor (optional).

If the SDT chosen in the first step is not the K2BAttributeValue SDT, the developer must implement an editor. The default editor, K2BAttributeValueCollectionEditor, may be used as a reference.

The editor must receive the EventTypeId as a parameter, and the mode (Display or Update are the modes that should be implemented).

Configure the metadata for the event type.

To do this, you must call the “SetEventTypeParameterMetadata” procedure. This procedure receives the following parameters:

  1. EventTypeId: The id for the event type being modified.

  2. EventTypeHasParameters: A boolean value indicating if the event has parameter support or not.

  3. EventTypeParametersEditor: A character value with the name of the web component used to display and edit parameter values. If no editor is specified, the default editor will be used. In that case, the value must be stored using the K2BAttributeValue SDT.

  4. EventTypeParametersInitialValue: The initial value for parameters, serializing the SDT defined in the first step.

Load parameter values in the application’s logic to evaluate if the event should be triggered.

Use the “GetEventTypeParametersById” and “SetEventTypeParametersById” to load and store parameter values.

The value being loaded or stored must be a character value, following the specification defined in the first step.

Update parameters using the configuration backend.

The end user may go to the event type configuration to change the parameter values.

Example: add parameters to a “large purchase order created” event type

To do this, the steps detailed in the previous section are followed.

Define how to store parameters.

To simplify this example, the K2BAttributeValue SDT will be used, allowing us to use the default editor.

(Optional) Define the parameters editor.

The default editor will be used.

Configure the metadata for the event type indicating that the event type accepts parameters.

To do this, we will execute the following code in the application’s data initialization procedure:

EventTypeDataInitialization
Event type initialization

(Error handling is omitted)

Load parameter values in the application’s logic to evaluate if the event should be triggered.

EventTypeParametersLoad
Getting event parameters

(Error handling is omitted)