User Guide > Triggers > Creating a System Event Trigger
 
Creating a System Event Trigger
There are many system events that can be set as conditions for a trigger action. The APIs—GetEnvironment and SetEnvironment—that are available in /lib/util/ can be called at any time to listen for a system-generated event.
These steps describe how to create a sample procedure, create the system event trigger, and then test the trigger.
To create a sample procedure to call GetEnvironment
1. Within Studio, create a sample SQL script procedure, named CallsGetEnvironment as follows:
PROCEDURE CallsGetEnvironment()
BEGIN
DECLARE tpath VARCHAR(4096);
DECLARE tname VARCHAR(4096);
DECLARE ttype VARCHAR(4096);
DECLARE tvalue VARCHAR(4096);
DECLARE result VARCHAR(4096);
CALL GetEnvironment('TRIGGER_PATH', tpath);
CALL GetEnvironment('TRIGGER_EVENT_NAME', tname);
CALL GetEnvironment('TRIGGER_EVENT_TYPE', ttype);
CALL GetEnvironment('TRIGGER_EVENT_VALUE', tvalue);
SET result = CASE
WHEN (ttype IS NULL) THEN 'NULL'
ELSE ttype
END||' trigger '||CASE
WHEN (tpath IS NULL) THEN 'NULL'
ELSE tpath
END||': '||CASE
WHEN (tname IS NULL) THEN 'NULL'
ELSE tname
END||' = '||CASE
WHEN (tvalue IS NULL) THEN 'NULL'
ELSE tvalue
END;
CALL Log(result);
END
 
When this procedure is executed by a system event, the results are written out to the log.
To create a system 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 System Event from the drop-down list in the Condition Type section.
5. Select a system event from the System Event Name drop-down list on the right.
6. For Action Type, select the type of action to be triggered from the drop-down list.
 
Field
Description
Execute Procedure
To see how it works, specify the path to the procedure CallsGetEnvironment in the Action section. Select Exhaust output cursors, if the procedure is a SQL script that contains a PIPE cursor.
Gather Statistics
To see how it works, select the data source /shared/examples/ds_orders as the data source to be scanned.
Reintrospect Data Source
To see how it works, select the data source /shared/examples/ds_orders as the data source to be re-introspected.
Send E-mail
To see how it works, specify the path to the procedure CallsGetEnvironment in the Action section.
7. In the Action section, enter the options for the action type. The options are described in the section Action Types for a Trigger and Action Pane.
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 (;).
8. Click the Info tab.
9. 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.
10. 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 system-event trigger
1. Select CacheRefreshFailure as the system event name in the Condition panel.
2. Select Send E-mail as the Action Type.
3. Specify the path to CacheRefreshFailure in the Resource Path field.
4. Refresh the cache of a broken view.
The specified mail recipients receive email notification and the result of running the path to procedure CallsGetEnvironment is written to the log.