Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Attach document as word file

(5) ShareShare
ReportReport
Posted on by 91
Dear team, 
I got a task which is save document(report) as word in document attachment factbox like system's Attach as PDF action but in docx.

  • Suggested answer
    YUN ZHU Profile Picture
    83,249 Super User 2025 Season 1 on at
    Attach document as word file
    Update: 
    Dynamics 365 Business Central: Save a document as a Word attachment (Attach as Word) – Customization
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,372 Super User 2025 Season 1 on at
  • Suggested answer
    YUN ZHU Profile Picture
    83,249 Super User 2025 Season 1 on at
    Attach document as word file
    Hi, hope the following can give you some hints. OneDrive can do the same thing.
    Dynamics 365 Business Central: Manage attachments in SharePoint (Save attachments externally and do not use BC capacity)
    Dynamics 365 Business Central: Preview files within BC (PDF, JPG, PPTX, DOCX, XLSX, TXT, CSV, MP4…… Most file types supported for previewing files in SharePoint) – No JavaScript control add-in
     
    Thanks.
    ZHU
  • Zain Mehmood Profile Picture
    3,927 Moderator on at
    Attach document as word file
     
    Great, can you please verify the answer.

    Let us know if there’s anything else you’d like to clarify or add — that way we could close the thread if everything’s resolved.

    Thanks!

    Zain

  • TB-28100618-0 Profile Picture
    91 on at
    Attach document as word file
    Yes, the customization creates action button that adds report to attachment factbox as docx is done.
    Now I'm wondering if I can get path of onedrive of my file so I can add it to Links part of Factbox.
    Thanks for the reply :)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,372 Super User 2025 Season 1 on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,372 Super User 2025 Season 1 on at
    Attach document as word file
    Are you looking solution to create a custom action that behaves just like the existing "Attach as PDF" action, but instead of generating and attaching a PDF, it should generate a Word (.docx) version of the report and attach it to the Document Attachment FactBox on the page?
  • Suggested answer
    Jainam M. Kothari Profile Picture
    7,938 on at
    Attach document as word file
    You can Integrate the same with SharePoint.
  • TB-28100618-0 Profile Picture
    91 on at
    Attach document as word file
    I have an another question.
    We can use Open In Onedrive or Edit in onedrive right?
    How to retrieve that sourcepath of the onedrive file?
  • TB-28100618-0 Profile Picture
    91 on at
    Attach document as word file
    Thanks for the replies,
    I mean the question was a customization that adds report to attachment factbox.
    Following works fine.
    action(AddtoAttachment)
                {
                    ApplicationArea = All;
                    Caption = 'Add to Attachment';
                    trigger OnAction()
                    var
                       
                        CareerMovementLedgerEntry: Record "Career Movement Draft";
                        ReportSelection: record "Report Selections";
                        Usage: Enum "Report Selection Usage";
                    begin
                        CareerMovementLedgerEntry := Rec;
                        CareerMovementLedgerEntry.SetRecFilter();
                        ReportSelection.SaveAsDocumentAttachment(
                            Usage::"Career Movement Draft".AsInteger(), CareerMovementLedgerEntry, CareerMovementLedgerEntry."Document No.", '', false);
                    end;
                }​​​​​​​
    [EventSubscriber(ObjectType::Table, Database::"Report Selections", 'OnBeforeSaveReportAsPDF', '', false, false)]
        local procedure OnBeforeSaveReportAsPDF(var ReportID: Integer; RecordVariant: Variant; var LayoutCode: Code[20]; var IsHandled: Boolean; FilePath: Text[250]; ReportUsage: Enum "Report Selection Usage"; SaveToBlob: Boolean; var TempBlob: Codeunit "Temp Blob"; var ReportSelections: Record "Report Selections")
        var
            ReportLayoutSelectionLocal: Record "Report Layout Selection";
            CustomLayoutReporting: Codeunit "Custom Layout Reporting";
            CustomerStatementSub: codeunit "Customer Statement Subscr";
            LastUsedParameters: Text;
            OutStream: OutStream;
        begin
            if ReportID = 78301 then begin
                TempBlob.CreateOutStream(OutStream);
                LastUsedParameters := CustomLayoutReporting.GetReportRequestPageParameters(ReportID);
                Report.SaveAs(ReportID, LastUsedParameters, ReportFormat::Word, OutStream, GetRecRef(RecordVariant));
                IsHandled := true;
            end;
        end;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,014

#2
YUN ZHU Profile Picture

YUN ZHU 950 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 624

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans