Hi, Readers.
Today I would like to talk about how to use System.Hyperlink Method to open a URL in a current session without opening a new tab in the browser.
About half a year ago, we discussed how to open a page in a new browser tab via AL (Run an object in a new tab). At that time we used System.Hyperlink Method.
System.Hyperlink Method: Passes a URL as an argument to an Internet browser, such as Windows Internet Explorer.
Syntax: System.Hyperlink(URL: String)
This method has an important remark.
Note:
At runtime, a new tab is opened in the same browser window where Dynamics 365 Business Central is running. If you pass an empty string, then no browser window is opened.
So, when using HyperLink method to open a URL, it will open in a new tab. This is standard behavior.
For example,
Test Video:
But recently I saw a very interesting question, is there anyway for a hyperlink to Business Central to open a URL in a current session without opening a new tab in the browser?
Yes, it takes a little trick.😀
Do you remember WebPageViewer Add-in (“Microsoft.Dynamics.Nav.Client.WebPageViewer”)? We discussed this topic about a year ago.
I added a video and a website to the Customer Card page by referring to the method of the page 1821 “Video Link”. Details can be found in the post above.
This time let’s look at the standard page 1821 “Video Link” again.
Choose Tell Me icon, enter Product Videos, and then choose the related link.
Default Video Library for Business Central:
PS: How to add new video links to the Product Videos page
When you click on the video title, you will find that instead of opening a new tab, it is now playing under the current session.
You can find some hints in the standard code of the page.
And there is a simple example of WebPageViewer Add-in in it.
So we can refer to this practice.
1. Create a new page to display the URL that needs to be opened. (Please add a function to set the URL.)
2. Set the URL and run the page.
It looks great.😁
Test video:
And we can also open another BC page in a current session.
Test Video:
Very interesting, isn’t it?😁 Give it a try!!!
Source Code:
pageextension 50100 CustomerListExt extends "Customer List"
{
actions
{
addfirst(processing)
{
action(RunHyperLink)
{
Caption = 'Run HyperLink';
ApplicationArea = All;
Promoted = true;
PromotedIsBig = true;
PromotedCategory = Process;
trigger OnAction()
begin
Hyperlink('https://yzhums.com/');
end;
}
action(RunHyperLinkInBC)
{
Caption = 'Run HyperLink in BC';
ApplicationArea = All;
Promoted = true;
PromotedIsBig = true;
PromotedCategory = Process;
trigger OnAction()
var
ZYHyperLink: Page "ZY HyperLink";
begin
ZYHyperLink.SetURL('https://yzhums.com/');
//ZYHyperLink.SetURL(GetUrl(ClientType::Current, Rec.CurrentCompany, ObjectType::Page, Page::"Customer List"));
ZYHyperLink.Run();
end;
}
}
}
}
page 50111 "ZY HyperLink"
{
Extensible = false;
Caption = 'HyperLink';
Editable = false;
PageType = Card;
layout
{
area(content)
{
group(Control5)
{
ShowCaption = false;
}
usercontrol(WebPageViewer; "Microsoft.Dynamics.Nav.Client.WebPageViewer")
{
ApplicationArea = All;
trigger ControlAddInReady(callbackUrl: Text)
begin
CurrPage.WebPageViewer.Navigate(URL);
end;
trigger Callback(data: Text)
begin
CurrPage.Close();
end;
}
}
}
var
URL: Text;
procedure SetURL(NavigateToURL: Text)
begin
URL := NavigateToURL;
end;
}
END
Hope this will help.
Thanks for reading.
ZHU
コメント