Document Attachment with Item Journal Table in Business Central
Business Central already provides the Document Attachment framework, but sometimes you need to extend it to work with additional tables.
In this blog, I’ll show you how I extended the Document Attachment functionality to support the Item Journal Line table.
By the end, you’ll be able to attach documents (like invoices, PDFs, or scanned files) directly to item journal lines and view them from the journal page.
First, extend the Document Type in the Document Attachment table to include a new option for Item Journal.
This makes it possible to tag an attachment specifically for an item journal line.
Step 2: Add Template Name and Batch Name Fields
The standard Document Attachment table doesn’t store the Template Name and Batch Name fields that are needed to uniquely identify an Item Journal Line.
So we extend the table with two new fields:
Step 3: Add a FactBox on the Item Journal Page
To make attachments visible from the journal, we add a FactBox on the Item Journal page.
This FactBox points to the Document Attachment List FactBox and links the relevant keys (Table ID, Template Name, Batch Name, and Line No.):
Now, the user can see attached documents for each journal line directly from the Item Journal.
Step 4: Create a Codeunit to Handle the Events
The last step is to hook into the Document Attachment events so that attachments are properly linked to Item Journal Lines.
We subscribe to three main events:
-
OnBeforeDrillDown (opens the record reference),
-
OnAfterOpenForRecRef (applies filters for the attachment list),
-
OnAfterInitFieldsFromRecRef (initializes fields when creating a new attachment).
With this extension in place:
-
Users can attach documents directly to Item Journal Lines,
-
The attachments are visible in a FactBox on the Item Journal,
-
The system automatically links attachments using Template Name, Batch Name, and Line No.,
-
The standard Document Attachment framework is extended in a clean, upgrade-safe way.
This approach can be applied to other journal or document tables too — just extend the Document Attachment table with the necessary keys and subscribe to the same events.
Thank you for your time,
Dharmendra Chavda
Comments
Post a Comment