User Guide > Triggers > Creating a User-Defined Event Trigger
 
Creating a User-Defined Event Trigger
When creating a user-defined event trigger, you first need to create a user-defined event that can function as a condition for a trigger action. Then you create the user-defined event trigger. Finally, you test the trigger.
Triggers are created like other TDV resources, but they cannot be published.
User-defined events are generated when the built-in procedure GenerateEvent (at /lib/util/) is called with an event name and value as its arguments.
User-defined event triggers execute once per cluster. Timer-based triggers can be designated as being cluster-aware and they fire on all cluster nodes on which the user-defined event is generated.
To create a user-defined event
1. Create a SQL script procedure named CallsGenerateEvent to call GenerateEvent, as in the following example:
PROCEDURE CallsGenerateEvent()
BEGIN
CALL GenerateEvent('runAReport', ' ');
END
 
This procedure calls GenerateEvent, which in turn creates a custom event with the name runAReport. Whenever this procedure is executed, GenerateEvent inserts the custom event named runAReport into the trigger system. The custom event is available for you to specify as a User Defined Event Name in the Condition section of a user-defined event trigger.
To create a user-defined event trigger
1. Right-click where you can add a new resource in the resource tree, and select New Trigger.
2. In the Input window, supply a name for the trigger, and click OK.
3. In the trigger editor that opens on the right, enable the trigger by selecting the Enable Trigger check box.
4. Select User Defined Event from the drop-down list in the Condition Type section.
5. In the User Defined Event Name field, supply a name for the event.
You can use a regular expression, for example, run*, to match more than one similar user-defined event name. For this example, you would supply the name runAReport.
6. For Action Type, select the type of action to be triggered from the drop-down list.
7. In the Action section, enter the options for the action type. The options are described in the section Action Pane.
Select Exhaust output cursors, if the procedure is a SQL script that contains a PIPE cursor.
For example, if you want email notifications sent, type and confirm the email addresses of the recipients to receive notification, as needed. You can specify a list of email addresses in the address fields by separating each one with a comma (,) or semicolon (;).Click the Info tab. Specify the Maximum Number In Queue field to the maximum number of times this trigger is to be fired if multiple periods have elapsed while a recurrence restriction prevents the trigger from firing. Most triggers should fire only once when the next available active operation window, but there might be cases when more than one trigger action should be initiated at the next opening of the recurrence restriction. This number should not be negative.
8. Save the trigger.
If the Save option is not enabled, select File > Refresh All to refresh the resources and enable the Save option.
To test your user-defined event trigger
Run the procedure CallsGenerateEvent that was created as described in Creating a User-Defined Event Trigger.