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

Dynamics 365 Business Central

Hi, Readers.
Last month, we have dicussed a new feautre in Business Central 2022 wave 1 (BC20), share a file through OneDrive (new Share action).

Business value:

Bring the best of Microsoft’s business and productivity suites together to initiate collaborative, review, and sharing activities without having to leave Business Central. Users benefit from a familiar sharing experience and reduce the need to download files to their device. This makes it easy to share files from the Report Inbox and document attachments through OneDrive for Business.

https://docs.microsoft.com/en-us/dynamics365-release-plan/2022wave1/smb/dynamics365-business-central/share-file-through-onedrive

And about six months ago, we also discussed how to implement your custom “Open in OneDrive” action in Dynamics 365 Business Central.

So in this post I would like to countine to talk about how to implement your custom “Share With OneDrive” action in Dynamics 365 Business Central. In fact, Microsoft has given the solution in the Dynamics 365 Business Central Launch Event 2022 Release wave 1.

Let’s try it. For example, adding “Share With OneDrive” action to Posted Sales Invoice (132, Document) page.
This is very similar to adding the “Open in OneDrive” action.

1. Create a page extension object to extend page 132 “Posted Sales Invoice”

2. Before adding Action, prepare the required logic.

3. Add “Share With OneDrive” action and logic.

Okay, next is the test.

Test Video:

Source Code:

pageextension 50999 PostedSalesInvExt extends "Posted Sales Invoice"
{
    actions
    {
        addafter(Email)
        {
            action(ShareWithOneDrive)
            {
                ApplicationArea = Basic, Suite;
                Caption = 'Share';
                ToolTip = 'Copy the file to your Business Central folder in OneDrive and share the file. You can also see who it''s already shared with.', Comment = 'OneDrive should not be translated';
                Image = Share;
                Enabled = ShareOptionsEnabled;
                Promoted = true;
                PromotedOnly = true;
                PromotedCategory = Process;
                PromotedIsBig = true;

                trigger OnAction()
                var
                    TempBlob: Codeunit "Temp Blob";
                    DocumentServiceManagement: Codeunit "Document Service Management";
                    InStr: InStream;
                begin
                    GetInvoice(TempBlob);
                    TempBlob.CreateInStream(InStr);
                    DocumentServiceManagement.ShareWithOneDrive(StrSubstNo(SalesInvoiceName, Rec."No."), '.pdf', InStr);
                end;
            }
        }
    }

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

    var
        ShareOptionsEnabled: Boolean;
        SalesInvoiceName: Label 'SalesInvoice_%1';

    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;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL