Extending DocXtender for Drag-and-Drop Document Attachments to Any Table and Page

Skip to main content

Extending DocXtender for Drag-and-Drop Document Attachments to Any Table and Page

You are here:

If a page in Business Central does not have the Document List factbox you will first need to add it to the page before DocXtender will work.

Starting with Business Central 25, you will need to create a codeunit to subscribe to 3 Business Central events in order for the factbox to allow attachments. Once the base attachment functionality works, DocXtender will also work.

The events to subscribe to are:

  1. OnAfterInitFieldsFromRecRef in the “Document Attachment” table
  2. OnAfterGetRefTable in the “Document Attachment Mgmt” codeunit
  3. OnAfterOpenForRecRef in the “Document Attachment Details” page

The Document Attachments table supports tables with up to 3 primary key fields: “No.”, “Document Type”, and “Line No.”. At minimum the “No.” field for the document attachment must be set, the other primary key fields are optional.

If the table you’re adding attachments to, whether it’s a custom table or built-in Business Central table, has more or different primary keys, you may not be able to use Document Attachments or may have to be creative in how you set the primary key values.

Once these events have been implemented, both the standard attachment functionality and DocXtender will work.

For Business Central prior to version 25:

DocXtender (2.1.7982.2 and newer) provides support using event subscribers to extend its drag-and-drop functionality for document attachments to any table or page in Business Central. The pattern follows the similar approach to extend the standard Business Central functionality for Document Attachments. You may wish to extend the standard functionality at the same time as extending the DocXtender functionality.

  1. Create a page extension.
  2. Add Document Attachment FactBox to the page extension.
  3. Add the four required procedures for event subscribers to specify the table and filters associated with the related record for the Document Attachment FactBox:
    • EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnGetCustomRecRefFromDocAttachment’, ”, false, false): sets the table for the related record when attaching documents using the drag and drop functionality.
    • EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnAfterOpenForRecRef’, ”, false, false): sets the filters for the related record when opening the attached document for DocXtender customizations.
    • EventSubscriber(ObjectType::Page, Page::”Document Attachment Details”, ‘OnAfterOpenForRecRef’, ”, false, false): sets the filters for the related record when opening the attached document for standard functionality.
    • EventSubscriber(ObjectType::Page, Page::”Document Attachment Factbox”, ‘OnBeforeDrillDown’, ”, false, false): (optional) sets the table for the related record when attaching documents using standard functionality.

Extending DocXtender Example

The following provides an example on how to extend DocXtender for the Released Production Order page:

  1. Create a page extension.
  2. Add the standard Document Attachment FactBox:
  1. Add procedures for the event subscribers:
    1. Set the table for the related record when attaching documents using the drag and drop functionality:
    1. Set the document number for the related record when opening the attached document for DocXtender customizations:
    1. Set the filters for the related record when opening the attached document for standard functionality:
    1. Set the table for the related record when attaching documents using standard functionality:
Was this article helpful?
5 out Of 5 Stars

1 rating

5 Stars 100%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Need help?

23 Comments

  1. Muaaz Deyab
    Muaaz Deyab April 13, 2026 at 9:42 am

    Hello ,

    Is there any subscriber or exposed procedure that I can use to trigger the document upload to sharepoint using API?
    Thanks,
    Muaaz

  2. luca
    luca April 6, 2026 at 1:36 am

    Hello,

    The code under the **“Sample Codeunit”** section is not being displayed correctly. I can see the heading and the beginning of the snippet (`codeunit 50200 “My Table Attachment Mgmt.”`), but the rest of the sample code is missing.

    I have tested this in both **Microsoft Edge** and **Google Chrome**, and the issue occurs in both browsers.

    Could you please check and make the sample code visible correctly?

    Thank you.

    • Travis Plett
      Travis Plett April 6, 2026 at 8:13 am

      I will track down that missing sample.
      Note that as of DocXtender 2.4 the majority of tables should now work out of the box as long as the “Documents” factbox is visible, so all old subscribers can be removed – this codeunit should not be required at all.

  3. Erik H
    Erik H November 27, 2025 at 4:06 pm

    The “Document Attachment Factbox” page is deprecated as of BC version 25.0, replaced by “Doc. Attachment List Factbox” which lacks an “OnBeforeDrillDown” event.
    Is it safe to replace with “Doc. Attachment List Factbox” and the “OnAfterGetRecRefFail” event?

  4. Opeyemi
    Opeyemi October 31, 2025 at 8:39 am

    We’re seeing an issue with DocXtender drag‑and‑drop on the General Journal: files upload successfully (the DocXtender UI reports “uploaded”), but the attachment/link does not appear in the page Links/Attachments factbox. I’d appreciate help reproducing and resolving this.

    Summary

    Product: DocXtender (IWX)

    Symptom: After dragging a file to the DocXtender drop zone while on a General Journal page/line, DocXtender reports the file uploaded but the document/link does not appear in the page’s Links/Attachments factbox (nor in table Document Attachment filtered for that record).

    Pages affected: General Journal (page “General Journal”) and Gen. Journal line context; we also prepared handling for G/L Entry.
    Expected: After upload, a Document Attachment record should be created for the current record (Table ID / No. / Line No.), and the Links/Attachments factbox (or Links systempart) should show the link immediately.

    What we’ve done so far

    1. Added the Document Attachment factbox to the General Journal page and to General Ledger Entries

    2. Implemented event subscribers to wire up Document Attachment relations for the Gen. Journal Line and G/L Entry contexts

    3.Verified that when DocXtender reports “uploaded”, a Document Attachment may be created (or at least DocXtender reports completion), but the created Document Attachment is not linked/visible in the Links/Attachments part for that Gen. Journal Line (the Links/Attachments UI remains empty).

    Repro steps (how we test)

    Open General Journal (page “General Journal”) and select a journal line (Gen. Journal Line context).
    Drag a file into the DocXtender drop zone.
    DocXtender UI shows “uploaded” (success message).
    Open the Document Attachment FactBox or Links tab — the new link does not appear.

    Questions / things we need from Insight Works

    Does DocXtender fire OnAfterOpenForRecRef for Gen. Journal Line RecRef when dragging to the drop zone? If so, is there any special handling required for Journal lines vs. master records?

    Which fields in the RecRef does DocXtender use for the record reference? (We assumed RecRef.Field(1) = primary key or RecRef.GetTable(…) yields typed record)

    Is DocXtender expected to create Document Attachment table rows or is it expected that an event subscriber must create/validate them? (We subscribed to Codeunit::”IWX DocXtender” OnAfterOpenForRecRef and attempted to set DocumentAttachment.Validate(“Table ID”, …) and Validate(“No.”, …).)

    If DocXtender reports “uploaded”, but the Links part does not show a link, is there a known reason?

    If DocXtender needs to call or we need to call Page::”Document Attachment Details”.OpenForRecRef(RecRef) or .RunModal() after setting the RecRef — is that required to make the association visible?

    Any example code or best practice for attaching documents (drag-and-drop) to lines (Gen. Journal Line) rather than header/card records? (Sample subscriber code that works with Gen. Journal Line would be ideal.)

    Are there any known compatibility issues with BC versions where the factbox was replaced with a list part, requiring different integration logic?

    Request

    Please advise the expected integration flow for DocXtender drag/drop on line-level pages (like Gen. Journal Line).

    If a patch or code sample is available to handle Gen. Journal Line (RecRef->Document Attachment mapping), please provide it or confirm the correct RecRef fields/order to use.

    Thank you — we rely on DocXtender heavily and would like to get drag-and-drop working for the General Journal lines (and ensure the uploaded file appears in the Links/Attachments factbox immediately).

    • Travis Plett
      Travis Plett October 31, 2025 at 2:07 pm

      Base Business Central does not support attachments (table Document Attachment 1173) or record links (table RecordLinks 2000000068) to multiple primary key records (not counting document type) and the primary key field must be 20 characters or less. Even if you find a way to make the Document factbox work in base Business Central, DocXtender will not recognize the multiple keys.

  5. Muaaz Deyab
    Muaaz Deyab November 19, 2024 at 11:53 am

    Hello,
    Is there any way we can change the of the file before creating it in SharePoint?

    • Travis Plett
      Travis Plett November 19, 2024 at 2:15 pm

      No, they are not configurable. The file name comes directly from the file that you dragged in and the path is based off of the document that it is attached to.

      • Muaaz Deyab
        Muaaz Deyab November 29, 2024 at 1:08 pm

        Hey Travis,
        I can see there is an event for OnAttachFile but when I try to debug this it is not being caught by the debugger, I have an issue where I have a table where users can upload documents for sales order and customer (based on field in the page) and then I want to move the link to the other page (Customer or Sales Order), additionally Is there any way I can modify the Json object, I want to change the folder Name where the file is created in the SharePoint ( ex: my table is called Attachment Entry so in the Share point I get the files from customer and sales order under this folder).

        • Travis Plett
          Travis Plett December 2, 2024 at 10:02 am

          No. The SharePoint subfolders will be created based on the card that the document is originally attached to and are not configurable or extendable:
          – SharePoint Host
          – SharePoint Site – (Site from setup)
          – SharePoint Library (Documents – non-configurable)
          – SharePoint Folder – (Folder from setup – optional)
          – Document Type – (i.e. Sales Order)
          – Document Number – (sub-folder)
          – Attachments – (files)
          DocXtender is not involved in the flow process, so the original link will remain usable. The SharePoint path would remain from where it was originally attached and would not be altered to reflect later documents.

  6. Colin R
    Colin R November 7, 2024 at 10:25 am

    If the file storage behavior is set to Share Point, and Document Attachments and Links FactBoxes are added to Production Orders, are there additional event subscribers needed so that when files are saved using DocXtender these are saved as links against the record instead of document attachments?

    • Travis Plett
      Travis Plett November 7, 2024 at 11:35 am

      The Business Central page must first have a “Document Attachment FactBox” pointing at a valid single record on any page you want to use DocXtender. The Attachment and Link factbox (not just the tab) must also be visible, so you may need to open personalization to add it. The events will be the same regardless of which method is used.

      When adding attachments to a new page, first check if the user can manually attach documents to the page using the base Business Central drag & drop function. Click the “Attach file” action (or the + sign if links) to try both browsing and drag & drop to upload a file instead of using DocXtender.

  7. Ron Dwyer
    Ron Dwyer June 27, 2024 at 8:24 am

    Hello –

    I’ve extended the base Document Attachment functionality so that it was able to handle tables with multi-field PKs.. And using the above information, was able to make DocXtender work in this situation as well.

    EXCEPT for one thing – after successfully attaching the file, the user is shown a confirmation saying “File attached successfully. Would you like to Open the Attachments Page?”

    If the user selects yes, the Attachment Details Page opens, but the file is not visible.

    If the user then closes the page (or selects No when they were prompted), the Document Attachment factbox CORRECTLY indicates that the file was attached, and if you drill down on that (which opens the Attachment Details Page), you can see the file.

    Are there any events that we can subscribe to with respect to the Confirmation box? I’d either like to suppress it entirely, or review the filters that are being applied to when the Attachment Details Page is opened.

    Rgs,

    rpd

  8. Muaaz Deyab
    Muaaz Deyab May 7, 2024 at 1:48 am

    Hello,
    Does it work too if i have more than one field in the primary key.
    I tried but it does not work

    [EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnGetCustomRecRefFromDocAttachment’, ”, false, false)]
    local procedure OnGetCustomRecRefFromDocAttachmentDocXtender(precDocumentAttachment: Record “Document Attachment”; var prrRecordRef: RecordRef; var lbRecordRefHandled: Boolean);
    var
    DocXtenderTest: Record “Document Checklist Line”;
    begin
    if not lbRecordRefHandled then begin
    case precDocumentAttachment.”Table ID” of
    Database::”Document Checklist Line”:
    begin
    prrRecordRef.Open(Database::”Document Checklist Line”);

    if DocXtenderTest.get(precDocumentAttachment.”Document Checklist Code”, precDocumentAttachment.Type, precDocumentAttachment.”Document Check Line No”) then begin
    prrRecordRef.GetTable(DocXtenderTest);
    lbRecordRefHandled := true;
    end;
    end;

    end;
    end;
    end;
    The PredocumentAttachement does not contain the fields i need, I added three field to the document attachment table and it work for the system functionality.
    Is there any subscriber where I can validate these fields or something else?

    • Travis Plett
      Travis Plett May 7, 2024 at 11:52 am

      The base Business Central page must have a “Document Attachment FactBox” pointing at a valid single record on any page you want to use DocXtender.
      As far as I can tell from looking at the tables, base Business Central does not support attachments (table Document Attachment 1173) or record links (table RecordLinks 2000000068) to multiple primary key records (not counting document type). You would need to check with your Business Central partner or Microsoft about how to add an attachment with dual primary keys.
      DocXtender only adds the drag & drop function – you still need to add the attachment function to the page first in base Business Central.

      • Muaaz Deyab
        Muaaz Deyab May 8, 2024 at 6:46 am

        Hello Travis ,
        Thanks for your reply. I tried to extend the standard functionality too but it does not work for multiple primary key, so i think i have to change my key to single key in order to get it to work.
        I already added the fact box to the page but i don’t think it will work ( maybe it is the same as the sales line or purchase line )
        I would appreciate if you have another solution.
        Thanks

        • Travis Plett
          Travis Plett May 8, 2024 at 9:48 am

          Once you have the Attachment and Link factboxes working in base Business Central, then DocXtender will be able to be used.

  9. Mike Gernhardt
    Mike Gernhardt March 5, 2024 at 1:15 pm

    I was able to get this working, at least the example above attaching to Released Production Orders (which was quite helpful as this is one of the pages that I needed attachments on).

    All the quotation marks in the examples are wrong. This is probably from the web page re-writting them to fancy quotes or something.
    There are line breaks also that need to be removed.

    ** in launch.json, set “startupObjectId”: 99000831,
    ** Not stated in instructions: You need to add IWX dependencies to app.json

    “dependencies”: [
    {
    “id”: “d50afbbf-aff3-4dac-bce7-8686b375b994”,
    “name”: “DocXtender”,
    “publisher”: “Insight Works”,
    “version”: “2.1.8635.2”
    }
    ],

    Here is copy/paste of my working code. It may break also when the page renders it, but it works.

    namespace MHW.DocXtender;

    using Microsoft.Manufacturing.Document;
    using Microsoft.Foundation.Attachment;

    pageextension 50106 “IWX Released Prod. Order” extends “Released Production Order”
    {
    layout
    {
    addfirst(factboxes)
    {
    part(“IWX Attached Documents”; “Document Attachment Factbox”)
    {
    ApplicationArea = All;
    Caption = ‘Attachments’;
    SubPageLink = “Table ID” = const(5405),
    “No.” = field(“No.”);
    }
    }
    }
    }

    codeunit 50106 “IWX codeunit”
    {
    EventSubscriberInstance = StaticAutomatic;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnGetCustomRecRefFromDocAttachment’, ”, false, false)]
    local procedure OnGetCustomRecRefFromDocAttachmentDocXtender(precDocumentAttachment: Record “Document Attachment”; var prrRecordRef: RecordRef; var lbRecordRefHandled: Boolean);
    var
    lrecProductionOrder: Record “Production Order”;
    begin
    // Set the table for the custom record, when attached documents using drag-and-drop with DocXtender
    if not lbRecordRefHandled then begin
    case precDocumentAttachment.”Table ID” of
    Database::”Production Order”:
    begin
    prrRecordRef.Open(Database::”Production Order”);
    if lrecProductionOrder.Get(lrecProductionOrder.Status::Released,
    precDocumentAttachment.”No.”) then begin
    prrRecordRef.GetTable(lrecProductionOrder);
    lbRecordRefHandled := true;
    end;
    end;
    end;
    end;
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnAfterOpenForRecRef’, ”, false, false)]
    local procedure OnAfterOpenForRecRefDocXtender(var precDocumentAttachment: Record “Document Attachment”; var prrRecordRef: RecordRef);
    var
    lfrFieldRef: FieldRef;
    lcodRecNo: Code[20];
    begin
    // Set filter for custom record when opening document attachment details
    case prrRecordRef.Number of
    Database::”Production Order”:
    begin

    lfrFieldRef := prrRecordRef.Field(2);
    lcodRecNo := lfrFieldRef.Value;
    precDocumentAttachment.SetRange(“No.”, lcodRecNo);
    precDocumentAttachment.SetRange(“Line No.”, 0);
    end;
    end;
    end;

    [EventSubscriber(ObjectType::Page, Page::”Document Attachment Details”, ‘OnAfterOpenForRecRef’, ”, false, false)]
    local procedure OnAfterOpenForRecRef(var DocumentAttachment: Record “Document Attachment”; var RecRef: RecordRef);
    var
    lfrFieldRef: FieldRef;
    lcodRecNo: Code[20];
    begin
    // Set filter for custom record when opening document attachment details
    case RecRef.Number of
    Database::”Production Order”:
    begin
    lfrFieldRef := RecRef.Field(2);
    lcodRecNo := lfrFieldRef.Value;
    DocumentAttachment.SetRange(“No.”, lcodRecNo);
    DocumentAttachment.SetRange(“Line No.”, 0);
    end;
    end;
    end;

    [EventSubscriber(ObjectType::Page, Page::”Document Attachment Factbox”, ‘OnBeforeDrillDown’, ”, false, false)]
    local procedure OnBeforeDrillDown(DocumentAttachment: Record “Document Attachment”; var RecRef: RecordRef);
    var
    lrecProductionOrder: Record “Production Order”;
    begin
    // Set the table for the custom record, when attaching documents manually
    case DocumentAttachment.”Table ID” of
    Database::”Production Order”:
    begin
    RecRef.Open(Database::”Production Order”);
    if lrecProductionOrder.Get(lrecProductionOrder.Status::Released, DocumentAttachment.”No.”) then
    RecRef.GetTable(lrecProductionOrder);
    end;
    end;
    end;
    }

  10. Brian Neufeld February 26, 2024 at 1:49 pm

    This is a test. Brian Neufeld will delete it.

  11. Travis Plett
    Travis Plett February 26, 2024 at 12:30 pm

    These DocXtender procedures do not add the ability to attach documents, it only adds a drag & drop interface. The attachment fasttab must be working in base Business Central before trying to use DocXtender. The above procedures only apply after you have the base Business Central attachment working first.

    Check that the user can manually attach documents to the page using the base Business Central attachment function. Click the “Attach file” action (or the + sign if links) to try both browsing and drag & drop to upload a file instead of using DocXtender. If that does not work, you may be trying to attach the file before the record has been created.

  12. Gary Wolf
    Gary Wolf February 15, 2024 at 5:49 am

    I copied and pasted these procedures into an EventSubscriber codeunit, to extend this to a custom master table, but the codeunit IWX DocXtender” is not being recognized. How can I fix this?

Leave A Comment

Table of Contents
Go to Top