Hi, Readers.
Today I would like to talk about how to restart session (refresh the browser) via AL.
I was asked this question recently. There are some controls on their page that need to be refreshed before they can be updated. However, having the user manually refresh the page is not a good way, so they want it to refresh automatically. Is there an easy way?
Yes, it can be done. Although I think it can be done using Page.Update([Boolean]) Method or a combination of Page.Close() Method and Page.Run() Method , it doesn’t matter.
Actually, there is the behavior in the standard functionality. When we set up Company Badge, the page is automatically refreshed when we close the page. More details about New Company Badge (System Indicator).
The Company Badge settings have changed. Refresh the browser (Ctrl+F5) to update the badge.
Test video: Because if the page is not refreshed, the Company Badge in the APP bar will not be updated.
Let’s see the background processing.
page 1 “Company Information”:
Key methods:
SessionSettings Data Type: Is a complex data type for passing user personalization settings for a client session as an object. The object contains properties that correspond to the fields in the system table 2000000073 User Personalization, including: App ID, Company, Language ID, Locale ID, Profile ID, Scope, and Time Zone. You can use the AL methods of the SessionSettings data type to get, set, and send the user personalization settings for the current client session.
SessionSettings.RequestSessionUpdate(Boolean) Method: Passes a SessionSettings object to the client to request a new session that uses the user personalization properties that are set in the object. The current client session is abandoned and a new session is started.
Syntax: SessionSettings.RequestSessionUpdate(saveSettings: Boolean)
Remarks
Within the scope of the RequestSessionUpdate method, it is not recommended to run code after the RequestSessionUpdate method call that requires client communication because the current client session will be abandoned.
Before the RequestSessionUpdate method is called, be sure that all user personalization properties in the SessionSettings object have values; otherwise the system default values will be used for empty properties. To help, you can use the Init method to populate the object with the values in the database.
More details about SessionSettings Data Type (A complex data type).
We can do the same thing. For example, after modifying the customer name, refresh the page.
Test video:
Source code:
pageextension 50110 CustomerCardExt extends "Customer Card"
{
layout
{
modify(Name)
{
trigger OnAfterValidate()
begin
if Rec.Name <> xRec.Name then begin
Message('The customer name has been modified. Refresh the browser (Ctrl+F5) to update.');
RestartSession();
end;
end;
}
}
local procedure RestartSession()
var
SessionSetting: SessionSettings;
begin
SessionSetting.Init();
SessionSetting.RequestSessionUpdate(false);
end;
}
We can also add an action to refresh the page.
Test video:
Source code:
pageextension 50110 CustomerCardExt extends "Customer Card"
{
actions
{
addfirst(Processing)
{
action("Refresh the browser (Ctrl+F5)")
{
Caption = 'Refresh the browser (Ctrl+F5)';
Image = Refresh;
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
trigger OnAction()
begin
RestartSession();
end;
}
}
}
local procedure RestartSession()
var
SessionSetting: SessionSettings;
begin
SessionSetting.Init();
SessionSetting.RequestSessionUpdate(false);
end;
}
Very simple, give it a try!!!😁
PS:
Switching a page to non-editable in real time via a field value
END
Hope this will help.
Thanks for reading.
ZHU
コメント