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.
To define parameters you must follow these steps:
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.
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).
To do this, you must call the “SetEventTypeParameterMetadata” procedure. This procedure receives the following parameters:
-
EventTypeId: The id for the event type being modified.
-
EventTypeHasParameters: A boolean value indicating if the event has parameter support or not.
-
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.
-
EventTypeParametersInitialValue: The initial value for parameters, serializing the SDT defined in the first step.
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.
The end user may go to the event type configuration to change the parameter values.
To do this, the steps detailed in the previous section are followed.
To simplify this example, the K2BAttributeValue SDT will be used, allowing us to use the default editor.
The default editor will be used.
To do this, we will execute the following code in the application’s data initialization procedure:
|
Event type initialization |
(Error handling is omitted)
|
Getting event parameters |
(Error handling is omitted)
|