A trigger is an action that the system should take automatically as a reaction to an activation. There are two activation methods:
- The user has recorded a change (insert, update or delete)
- An activator runs at regular intervals and evaluates an expression. If this returns values, the action is triggered.
Open window WKF003.
It allows you to determine the instant when an action will be triggered
1. "Activation's conditions" Section- Table to be supervised: select the table in which you want to monitor user actions. You will have access to the @idrcod of this table in this tab. This idrcod changes to @idrcodprov in the "Processing after activation" tab - Table of treatment: select the table in which you want to perform treatment after the trigger. If the processing table is different from the monitored table, you must enter a query in the "Affected records after the treatment" field to identify the idrcod (s) linked between the monitored table and the processing table. The resulting idrcods will become @idrcods in the "Processing after activation" tab. - Order: if several triggers are activated in the same operation, you can determine the order in which they will be triggered by assigning an order in this field - Insert, Update and Suppression: specify whether the trigger should activate following an INSERT, UPDATE or DELETE from the user *.
*Nota Bene: If you want this trigger to be activated automatically following a calculation at a predetermined time (activator), leave the Insert, Update and Suppression boxes empty, and enter a request in the "Activator" field. (See below).
2. "Advanced condition" SectionIt is possible to enter a request here which will be evaluated (in "IF EXISTS" format) throughout the transaction to determine whether the trigger should be triggered again. Please note, if you want a trigger to be able to activate more than once within a transaction, the "Allow recursion for this trigger" box in the main section of the window must be checked. By checking the box "Does not exist", the registered request will be evaluated as "IF NOT EXISTS".
3. “Affected records after the treatment” FieldIf the monitored table is different from the processing table, you must enter a query to identify the idrcods to be processed (i.e. make the link between the monitored table vs the processing table)
Example: monitored table = PRIMPosteCandidat. Table processed = PRIMPoste. Then the field "Records affected by processing" would contain a SELECT like this: SELECT p.idrcod FROM PRIMPostCandidate pc INNER JOIN PRIMPoste p ON pc.poscod = p.posocod WHERE pc.idrcod = @idrcod Where @idrcod is the idrcod of the monitored table.
4. "Conditions on the target table fields (Old value)" Section.The conditions indicated here are evaluated before the transaction. Thus, if a field monitored here changes during the transaction, so that the condition is no longer met, the trigger will not be able to fire a second time during the transaction. Please note, if you want a trigger to be able to activate more than once within a transaction, the "Allow recursion for this trigger" box in the main section of the window must be checked.
5. "Conditions on the target table fields (after the changes)" SectionThe conditions indicated here are evaluated when the user has attempted to make their modification. In these 2 sections, it is possible to specify columns that are present in the structure of the operational flow. It is possible to establish the evaluation order by indicating it in the "Order" column. It is also possible to create groups with opening / closing parentheses ("Opened group" and "Closed group" columns) to form logical conditions of the type "((condition A OR condition B) AND condition C"). In "Value to test", write a condition as follows: - IS NULL - IS NOT NULL - = 2 - = "A" - IN (1,2,3) - IN ("A", "B", "C") - Etc.
6. "Activator" sectionEnter the query to test in the SQL field. It must return an idrcod list or just 1 to signify a systematic trigger. Then check the activator(s) to which you want to link the trigger. This will determine when you want to evaluate the above expression. Please note that activators must be created and activated in the activator management window. |
1. Event generated following the trigger (optional): Select an event to insert. The type of event must be linked to the treatment table and be checked "trigger insertion".
2. Task generated after the trigger (optional): Select a task to generate. The type of task must be linked to the processing table and be checked "trigger insertion".
3. Scripts: insert the SQL script to be executed following the trigger. It is better to call procedures rather than injecting full queries into them, to facilitate maintenance operations and ensure smooth transitions to future versions.
|