Hi, Readers.
In Dynamics 365 Business Central: How to substitute a report for another report via AL, we discussed how to substitute a report for another report via AL.
Today I would like to talk about another interesting topic, how to substitute a page for another page via AL. I was asked this question recently.
In Business Central, pages are the main way to display and organize data. Pages are the primary object that a user will interact with and have a different behavior based on the type of page that you choose.
First of all, different from report, Microsoft has not prepared any standard events in advance. So we have to solve this problem in other ways. The method to consider is very simple. While opening the original page, open a new page and close the original page.
But maybe you have tried it, CurrPage.Close() method does not work in trigger OnOpenPage(). Let’s look at a simple example, when the standard Payment Methods page opens, open the Payment Terms page and close the Payment Methods page.
pageextension 50115 PaymentMethodsExt extends "Payment Methods"
{
trigger OnOpenPage()
begin
Page.Run(Page::"Payment Terms");
CurrPage.Close();
end;
}As a result, this will open the Payment Terms page first, then the Payment Methods page (Sometimes the page cannot be opened and displays blank page).
Test video:
Therefore, the above approach is not very good. At this time, we can change our thinking, open a new page, and then prevent the original page from opening.
We can use Error(”), the Error method causes execution of AL code to stop. For example,
pageextension 50115 PaymentMethodsExt extends "Payment Methods"
{
trigger OnOpenPage()
begin
Page.Run(Page::"Payment Terms");
Error('');
end;
}Great. Using this method, we can allow users to jump to our customized page when they open the standard page.
The second question is, if it is not a list page, but an associated Card page or Document page, what should be done?
Starting with Business Central 2025 wave 1 (BC26), this is no longer a problem, as we can extend the CardPageId Property. More details: Extend CardPageId on list and listpart pages (Support modification of CardPageID on PageExtensions)
But for previous versions, we need a little trick, although I personally don’t recommend. Taking the Customer Card as an example, I first created a very simple custom Customer Card page.
Then when you edit or create a new Customer in the Customer List, you will automatically be redirected to this new page.
PS: How to open a page in Create/New mode via AL
Test video: Other than deletion, the same behavior as the standard.
Test code:
pageextension 50115 CustomerCardExt extends "Customer Card"
{
trigger OnOpenPage()
var
Cust: Record Customer;
ZYCustomerCard: Page "ZY Customer Card";
begin
if Cust.Get(Rec."No.") then begin
ZYCustomerCard.SetRecord(Cust);
ZYCustomerCard.Editable := CurrPage.Editable;
ZYCustomerCard.Run();
end else begin
Cust.Init();
Cust."No." := '';
Cust.Insert(true);
ZYCustomerCard.SetRecord(Cust);
ZYCustomerCard.Editable := CurrPage.Editable;
ZYCustomerCard.Run();
end;
Error('');
end;
}
page 50102 "ZY Customer Card"
{
Caption = 'ZY Customer Card';
PageType = Card;
SourceTable = Customer;
RefreshOnActivate = true;
ApplicationArea = All;
layout
{
area(Content)
{
group(General)
{
Caption = 'General';
field("No."; Rec."No.")
{
ToolTip = 'Specifies the number of the customer.';
}
field(Name; Rec.Name)
{
ToolTip = 'Specifies the name of the customer.';
}
field("Salesperson Code"; Rec."Salesperson Code")
{
ToolTip = 'Specifies the value of the Salesperson Code field.';
}
field(Blocked; Rec.Blocked)
{
ToolTip = 'Specifies the value of the Blocked field.';
}
}
}
}
}Very good, I hope this approach can give you some new ideas, give it a try!!!😁
PS:
1. Dynamics 365 Business Central: Switching a page to non-editable in real time via a field value
END
Hope this will help.
Thanks for reading.
ZHU
コメント