Identify different page, control, and action triggers

Completed

Page triggers are run when something happens on or with the page. You can run code when a user opens or closes a page or when a new record is retrieved from the database.

In AL, you can define the triggers under the layout and actions section. The following screenshot shows a list of the available page triggers.

List of the available Page triggers in AL.

The following are commonly used page triggers:

  • OnInit - Use when the page is loaded but before the controls are available.

  • OnOpenPage - Use when the page is initialized and the controls are available.

  • OnAfterGetRecord - Use when a record has been retrieved but not yet displayed.

  • OnAfterGetCurrRecord - Use after the current record is retrieved from the table.

The OnInit trigger usually shows or hides parts and controls with the Visible property of the control.

Alongside the page triggers are control triggers. Control triggers are used on page fields. To define a control trigger, you need to specify it in the control section after the control properties.

Example of a Control trigger being used in AL.

The following triggers are available for a field on a page:

  • OnAssistEdit - Triggered when someone uses the Assist Edit button. Typically, this trigger is used with No. Series to select another number series.

  • OnDrillDown - Triggered when a user selects a control that acts as a drill-down control. This trigger is typically used with FlowFields. When you select a FlowField, it will display the records that make up the calculation for the FlowField. OnDrillDown can also be used with HeadlineParts on a Role Center page to perform an action when the headline is selected.

  • OnLookup - Triggered when a user selects a drop-down control that performs a lookup. This trigger has the same behavior as the OnLookup trigger on the table. We recommend that you put the code on the table level as much as possible.

  • OnValidate - Triggered when a user enters a value in a field and then leaves the field. This trigger has the same behavior as the OnValidate trigger on the table level.

The OnAssistEdit trigger is used on master tables to set the number series that is used for a record. The next screenshot shows the implementation of the OnAssistEdit trigger for the No. field on the Customer Card page.

Example of an OnAssistEdit on the Customer Card.

The OnAssistEdit trigger calls a function on the Customer table. This function uses another codeunit to show users the available number series and handles the No. Series logic.

Example of an AssistEdit on the Customer table.

Action triggers

Every action on a page has an OnAction trigger. You can use this trigger to write code that is run when a user selects the button on a page. You can also use the RunObject property to open another page or call a function in a codeunit.

If you need to write more logic before opening a certain page, you can use the OnAction trigger.

If the RunObject property and the OnAction trigger are used simultaneously, both will be run, which can lead to conflicts. Be careful to use either the RunObject property or the OnAction trigger, but not both.

actions
{
    area(Processing)
    {
        action(ActionName)
        {
            Image = Action;

            trigger OnAction()
            begin

            end;
        }
    }
}