Hello Readers,
Today I will explain to you the concept of page triggers in the Microsoft Dynamics 365 Busines Central.
So let's start.
What is Page Trigger?
Ans: Certain predefined events that occur to a page can cause the system to execute a user-defined function. Triggers activate a method when a certain event occurs.
There are different types of triggers available in business central. I will explain you one by one with examples.
trigger OnInit()
begin
end;
This Trigger initializes the user define variable on the page.
Example of OnInit Trigger.
Af First I have created a table "SARAB Test Table". Please check the code below for table creation
table 59100 "SARAB Test Table"
{
DataClassification = CustomerContent;
fields
{
field(1; "Entry No."; Integer)
{
DataClassification = CustomerContent;
AutoIncrement = true;
}
field(4; "Result"; Integer)
{
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "Entry No.")
{
Clustered = true;
}
}
}
After Creating the table then I have created the Card Page using this table. please find the code below.
page 59100 "SARAB Test Page Card"
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Administration;
SourceTable = "SARAB Test Table";
Caption = 'Test Card Page';
layout
{
area(Content)
{
group(Calculate)
{
field("Int A"; "Int A")
{
ApplicationArea = All;
}
field("Int B"; "Int B")
{
ApplicationArea = All;
}
field(Result; rec.Result)
{
ApplicationArea = All;
}
}
}
}
trigger OnInit()
begin
"Int A" := 10;
"Int B" := 20;
end;
var
"Int A": Integer;
"Int B": Integer;
}
After going through the above code you will find that I have declared two variables Int A, Int B of Integer type. Then I have initialized the two variables as Int A = 10; Int B = 20; inside the trigger OnInit() .
As shown below Image.
trigger OnInit()
begin
"Int A" := 10;
"Int B" := 20;
end;
var
"Int A": Integer;
"Int B": Integer;
Now to open the card page I will create a list page. Please check the code below for list page creation
page 59101 "SARAB Test Page List"
{
PageType = List;
ApplicationArea = All;
UsageCategory = Administration;
SourceTable = "SARAB Test Table";
CardPageId = "SARAB Test Page Card";
Caption = 'Test List Page';
layout
{
area(Content)
{
repeater(Group)
{
field("Entry No."; rec."Entry No.")
{
ApplicationArea = All;
Editable = false;
}
field(Result; rec.Result)
{
ApplicationArea = All;
Editable = false;
}
}
}
}
}
Now I will show you in business central. How trigger OnInit() works and its usage.
In the above video you have seen the value of Int A and Int B Comes Automatically.
Comments
Post a Comment