web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

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

Attach document as word file

(7) ShareShare
ReportReport
Posted on by 101
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.

I have the same question (0)
  • Verified answer
    Zain Mehmood Profile Picture
    4,173 Most Valuable Professional on at
    Attach document as word file
    Hi,

    Business Central doesn’t support Attach as Word out of the box like it does with PDF, but you can achieve it with a small extension.
     
    Custom approach:
    1. Use Report.SaveAs with ReportFormat::Word to generate the .docx version.
    2. Save the result into a TempBlob.
    3. Create a new record in "Document Attachment" table.
    4. Set the file content and name, then insert the record.
    It’s basically the same logic used in Attach as PDF, 

    Regards,
    Zain
  • Suggested answer
    Jainam M. Kothari Profile Picture
    12,148 Super User 2025 Season 2 on at
    Attach document as word file
    Hello,
     
    It is working fine for me.
     
  • TB-28100618-0 Profile Picture
    101 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;
  • TB-28100618-0 Profile Picture
    101 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?
  • Suggested answer
    Jainam M. Kothari Profile Picture
    12,148 Super User 2025 Season 2 on at
    Attach document as word file
    You can Integrate the same with SharePoint.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,517 Super User 2025 Season 2 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
    Khushbu Rajvi. Profile Picture
    19,517 Super User 2025 Season 2 on at
  • TB-28100618-0 Profile Picture
    101 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 :)
  • Zain Mehmood Profile Picture
    4,173 Most Valuable Professional 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

  • Suggested answer
    YUN ZHU Profile Picture
    93,438 Super User 2025 Season 2 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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,674

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,580

#3
YUN ZHU Profile Picture

YUN ZHU 2,115 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans