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

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

You are here:

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 three (minimum) 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 filters 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?

8 Comments

  1. 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.

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

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

    This is a test. Brian Neufeld will delete it.

  4. 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.

  5. 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

Go to Top