Dynamics 365 Business Central: How to register and play video within BC (embed video in BC)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to register and play video within Business Central.
If you’re new to Business Central, you can launch the introduction videos from Business Central. This is very helpful for technical people who don’t like documentation.

Choose the Tell Me icon, enter Product Videos, then choose the related link.

You can see some videos prepared by Microsoft. Click Title.

The video will be played on the Business Central page. More details: Visit Our Video Library

So, how is this done? Is it possible to add additional videos? Yes, I will share this briefly in this post.
First let’s talk about how to add a new video. This time we are going to use the Register() method in codeunit 3710 Video. Register() method has method overloading, you just need to use one of them according to your needs.

But page 1470 “Product Videos” is not extensible.

And, the data is inserted when the page is opened.

Fortunately, there are the following event to subscribe to😁.

Let’s see a simple example.

Great.

But please note that when adding videos from Youtube, we need Embed URL. If you just add a normal URL, the following error will be displayed.

Here are two simple ways to get the Embed URL of the video.
1. Right click on the video and click Copy embed code

Then add the following URL.

2. Click Share.

Choose Embed.

You can also find this URL.

Well, the next question is how to play it internally. This is not very difficult, just use the Play() method in codeunit 3710 Video.

That’s how it’s done in the standard.

Let’s see another simple example.
Add a new Video URL field to Item Card to let users enter a video URL and then add an action to play the video.

Great.

Test video:

Very simple, give it a try!!!😁

Source code: Github

codeunit 50118 RegisterNewVideos
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::Video, OnRegisterVideo, '', false, false)]
    local procedure OnRegisterVideo(var Sender: Codeunit Video);
    begin
        Sender.Register('801277c3-645a-4471-a40b-d6cfdad7112e', 'What''s new: Business Central developer tools (2023 release wave 2)', 'https://www.youtube.com/embed/TY82NR2hGEg', Enum::"Video Category"::Customize);
        Sender.Register('801277c3-645a-4471-a40b-d6cfdad7112e', 'Get low friction go lives and optimize your investments with telemetry data', 'https://www.youtube.com/embed/F_pssS0FtUc', Enum::"Video Category"::ReadyForBusiness);
        Sender.Register('801277c3-645a-4471-a40b-d6cfdad7112e', 'Introducing: Analyze data on lists and queries', 'https://www.youtube.com/embed/qmLVKyHRhNc', Enum::"Video Category"::ReadyForBusiness);
    end;
}

tableextension 50115 ItemExt extends Item
{
    fields
    {
        field(50000; VideoURL; Text[100])
        {
            Caption = 'Video URL';
            Description = 'Embed video';
            DataClassification = CustomerContent;
        }
    }
}
pageextension 50115 ItemCardExt extends "Item Card"
{
    layout
    {
        addafter("Purchasing Code")
        {
            field(VideoURL; Rec.VideoURL)
            {
                ApplicationArea = All;
                ToolTip = 'Specifies the Video Url, such as youtube.';
            }
        }
    }
    actions
    {
        addlast(processing)
        {
            action(PlayVideo)
            {
                Caption = 'Play Video';
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                ApplicationArea = All;
                image = Picture;

                trigger OnAction()
                var
                    VideoCod: Codeunit Video;
                begin
                    VideoCod.Play(Rec.VideoURL);
                end;
            }
        }
    }
}

PS:
1. If you don’t need to open video in Business Central, just use Hyperlink(Text) Method. This does not require an Embed URL.

2. In fact, we can also do without the Play() method in codeunit 3710 Video. We can use WebPageViewer Add-in. More details: Using Hyperlink() Method to open a URL in a current session without opening a new tab in the browser
For example,

The result is the same as the Play() method.

Source code: Github

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://www.youtube.com/watch?v=qmLVKyHRhNc');
                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://www.youtube.com/embed/TY82NR2hGEg');
                    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

コメント

Copied title and URL