Triggers

Triggers are a powerful tool for experienced users. With triggers it is possible to copy (even calculated) values from a table to another linked one. You should only use triggers, if the same result cannot be achieved with a simple formula field.

A trigger is an operation that is executed each time when the corresponding field is changed.

You can create a trigger on any data or table reference field. Go to the field settings and expand “More options”. There you’ll find the option “Trigger after update”. Clicking on that option will open the formula editor. For triggers, the formula editor sports an additional tab: “Commands”. Commands allow you to assign calculated values to data fields within the same table.

Example

A good example for using triggers effectively are invoices. Consider an invoice which consists of several invoice items. Each invoice item refers to an article in your stock. At any given point in time an article has a specific sales price. But that sales price may change over time.

When creating an invoice item for the invoice, the user has to select the corresponding article and assign a quantity. The straight forward approach to calculate the invoice item’s total would be to define a formula like “Quantity * Article.Price”. But as stated above, the article’s price may change later on, which would render the invoice invalid.

To cope with changing prices, the better solution is, to define a data field for the unit price right in the invoice item table. Also, that would allow for special rebated prices on each invoice. Drawback: Now the user has to enter the article price manually each time he creates a new invoice item.

Here, triggers come into play. A trigger on the table reference Article can do that work automatically: Just define “Price := Article.Price” to copy the price, each time the article is assigned / changed.