A Trigger function is a Project function invoked from the On Change LU table property when the LU table's data has been modified.
To create a Trigger function, refer to the steps in How to Create Project Functions.
When creating a Trigger function, make sure that:
The TableDataChange data type exposes a set of methods which allow getting additional information about the change such as:
The Trigger function analyzes the change using the above information and executes business logic, for example, write the old and the new values into a log table.
A Trigger function must be attached to one or more LU tables in the LU Schema to be executed when there are changes in an LU table's data.
Do the following:
Go to Project Tree > Logical Units > [LU Name] > Tables > [Table Name] to display the Table Schema window.
To attach the Trigger function using the LU Table Properties tab, click the three dots next to the On Change option to open the Trigger Item Collection Editor.
Click Add and then click the area next to Name to display the list of Trigger functions. Select the function from the list.
(Optional) To add more Trigger functions to the same LU table, click Add again and select the additional functions. Define the Trigger functions execution order using the arrows next to the function names in the Editor.
Click OK to close the Editor and then Save the table.
To remove a Trigger function from the LU table, do the following:
Go to Project Tree > Logical Units > [LU Name] > Tables > [Table Name] to display the Table Schema window.
In the Table Properties tab, click the three dots next to the On Change option to open the Trigger Item Collection Editor.
Select the function and click Remove.
Click OK to close the Editor and then Save the table.
Create a new function with Function Type = Trigger Function.
Write the business logic, for example if the change type = INSERT, populate the table name, the old values and the new values into a specific log table defined in the Fabric Common DB.
String tbl = tableDataChange.getTable().toString();
DataChangeType change = tableDataChange.getType();
List newValuesList = tableDataChange.newValuesAsList();
String newValues = newValuesList.toString();
List oldValuesList = tableDataChange.oldValuesAsList();
String oldValues = oldValuesList.toString();
if( change == DataChangeType.INSERT) {
Db ci = db("fabric");
ci.beginTransaction();
ci.execute("insert into DATA_CHANGES values (?,?,?)",tbl,oldValues,newValues);
ci.commit();
}
A Trigger function is a Project function invoked from the On Change LU table property when the LU table's data has been modified.
To create a Trigger function, refer to the steps in How to Create Project Functions.
When creating a Trigger function, make sure that:
The TableDataChange data type exposes a set of methods which allow getting additional information about the change such as:
The Trigger function analyzes the change using the above information and executes business logic, for example, write the old and the new values into a log table.
A Trigger function must be attached to one or more LU tables in the LU Schema to be executed when there are changes in an LU table's data.
Do the following:
Go to Project Tree > Logical Units > [LU Name] > Tables > [Table Name] to display the Table Schema window.
To attach the Trigger function using the LU Table Properties tab, click the three dots next to the On Change option to open the Trigger Item Collection Editor.
Click Add and then click the area next to Name to display the list of Trigger functions. Select the function from the list.
(Optional) To add more Trigger functions to the same LU table, click Add again and select the additional functions. Define the Trigger functions execution order using the arrows next to the function names in the Editor.
Click OK to close the Editor and then Save the table.
To remove a Trigger function from the LU table, do the following:
Go to Project Tree > Logical Units > [LU Name] > Tables > [Table Name] to display the Table Schema window.
In the Table Properties tab, click the three dots next to the On Change option to open the Trigger Item Collection Editor.
Select the function and click Remove.
Click OK to close the Editor and then Save the table.
Create a new function with Function Type = Trigger Function.
Write the business logic, for example if the change type = INSERT, populate the table name, the old values and the new values into a specific log table defined in the Fabric Common DB.
String tbl = tableDataChange.getTable().toString();
DataChangeType change = tableDataChange.getType();
List newValuesList = tableDataChange.newValuesAsList();
String newValues = newValuesList.toString();
List oldValuesList = tableDataChange.oldValuesAsList();
String oldValues = oldValuesList.toString();
if( change == DataChangeType.INSERT) {
Db ci = db("fabric");
ci.beginTransaction();
ci.execute("insert into DATA_CHANGES values (?,?,?)",tbl,oldValues,newValues);
ci.commit();
}