Skip to content

DocXtender · How-to guides

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

Last updated April 22, 2026

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:
pageextension 50600 "IWX Released Prod. Order" extends "Released Production Order"
  1. Add procedures for the event subscribers:
    1. Set the table for the related record when attaching documents using the drag and drop functionality:

[EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnAfterOpenForRecRef’, ”, false, false)]

local procedure HandleOnAfterOpenForRecRefDocXtender(var precDocumentAttachment: Record “Document Attachment”; var prrRecordRef: RecordRef)

var

lfrFieldRef: FieldRef;

lcodRecNo: Code[20];

begin

case prrRecordRef.Number of

Database::”Production Order”:

begin

lfrFieldRef := prrRecordRef.Field(2);

lcodRecNo := lfrFieldRef.Value;

precDocumentAttachment.”No.” := lcodRecNo;

end;

end;

end;

    1. Set the document number for the related record when opening the attached document for DocXtender customizations:

[EventSubscriber(ObjectType::Codeunit, Codeunit::”IWX DocXtender”, ‘OnAfterOpenForRecRef’, ”, false, false)]

local procedure HandleOnAfterOpenForRecRefDocXtender(var precDocumentAttachment: Record “Document Attachment”; var prrRecordRef: RecordRef)

var

lfrFieldRef: FieldRef;

lcodRecNo: Code[20];

begin

case prrRecordRef.Number of

Database::”Production Order”:

begin

lfrFieldRef := prrRecordRef.Field(2);

lcodRecNo := lfrFieldRef.Value;

precDocumentAttachment.”No.” := lcodRecNo;

end;

end;

end;

    1. Set the filters for the related record when opening the attached document for standard functionality:
[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;
    1. Set the table for the related record when attaching documents using standard functionality:
[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;

View this article as Markdown

Still need help?

Ask other Business Central users in the Insight Works community, or send the details to the support team. Include the steps you took and any error message you saw.