Implement your custom “Open in OneDrive” action in Dynamics 365 Business Central

Dynamics 365 Business Central

Hi, Readers.
Last month, we have dicussed Cloud Storage and Open in OneDrive in Dynamics 365 Business Central 2021 Wave2 (BC19).

Today I would like to talk about how to implement your custom “Open in One drive” action. Actually this is an example from Microsoft.

First you need to access to OneDrive from Business Central.
The following is extracted from Cloud Storage and Open in OneDrive.

Open the My setting in BC19, you will see an additional item.

Cloud Storage
Specifies a link to explore your Business Central folder in OneDrive. Select the link to open the folder in a new window.

You can click the value of the Cloud Storage field.

Then a login window will pop up.

Note:
1. You need always allow pop-ups and redirects from https://businesscentral.dynamics.com for your browser.

Otherwise, an error will occur.

Failed to acquire an access token.

2. Need admin approval

Business Central Integration to SharePointmicrosoft.com

Business Central Integration to SharePoint needs permission to access resources in your organization that only an admin can grant. Please ask an admin to grant permission to this app before you can use it.

3. You need a license for Office 365, otherwise, OneDrive cannot be opened.

If there is no problem with the verification, the page will jump to OneDrive.

Test video:

Next, let’s add custom “Open in One drive” action to Posted Sales Invoice page.
The key point for Open in OneDrive feature.

DocumentServiceManagement: Codeunit "Document Service Management";

procedure OpenInOneDrive(FileName: Text, FileExtension: Text, InStream: InStream)

Source Code:

pageextension 50999 PostedSalesInvExt extends "Posted Sales Invoice"
{
    actions
    {
        addafter(Email)
        {
            action(OpenInOneDrive)
            {
                ApplicationArea = Basic, Suite;
                Caption = 'Open in OneDrive';
                ToolTip = 'Copy the file to your Business Central folder in OneDrive and open it in a new window so you can manage or share the file.', Comment = 'OneDrive should not be translated';
                Image = Cloud;
                Enabled = ShareOptionsEnabled;
                Promoted = true;
                PromotedOnly = true;
                PromotedCategory = Category6;
                PromotedIsBig = true;

                trigger OnAction()
                var
                    TempBlob: Codeunit "Temp Blob";
                    DocumentServiceManagement: Codeunit "Document Service Management";
                    InStr: InStream;
                begin
                    GetInvoice(TempBlob);

                    TempBlob.CreateInStream(InStr);
                    DocumentServiceManagement.OpenInOneDrive(StrSubstNo(SalesInvoiceName, Rec."No."), '.pdf', InStr);
                end;
            }
        }
    }

    var
        ShareOptionsEnabled: Boolean;
        SalesInvoiceName: Label 'Sales Invoice %1';

    trigger OnOpenPage()
    var
        DocumentSharing: Codeunit "Document Sharing";
    begin
        ShareOptionsEnabled := DocumentSharing.ShareEnabled();
    end;

    local procedure GetInvoice(var TempBlob: Codeunit "Temp Blob")
    var
        ReportSelections: Record "Report Selections";
        RecRef: RecordRef;
    begin
        RecRef.GetTable(Rec);
        RecRef.SetRecFilter();

        ReportSelections.GetPdfReportForCust(TempBlob, ReportSelections.Usage::"S.Invoice", RecRef, Rec."Sell-to Customer No.");
    end;
}

Test Video:

PS: You can choose Keep both or Overwrite when the file exists.

If you choose Keep both, a new file will be copied.

If you choose Overwrite, the old file will be updated and you can see version history in OneDrive.

Other information from Microsoft:

Update 2022/05/18: Implement your custom “Share With OneDrive” action in Dynamics 365 Business Central

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL