How to Attach Documents to any Record of any Table in Business Central

Introduction:

Attachment is a relatively new functionality in Business Central. Unlike Links you need not store the links to the document but attach the document itself. In this blog I’ll be showing how to customize Business Central to attach documents to any table.

Pre-requisite:

VS Code
Microsoft Dynamics Business Central

Demonstration:

Attachments are stored in Table 1173 Document Attachment Table. Using the standard document attachment table functionality does not support attaching on all the tables / pages. Currently in Business Central attachment functionality is allowed only on Master and Documents.

  • Adding a field in Document Attachment Table to classify if you want to attach documents for different purpose. In this case I wanted to Attach two types of Documents. So I created an Option Type with Scale Ticket and Lab Report which will be set during the insertion of attachment in the Page. Refer: SaveAttachment2 function.

  • Creating a Custom page with Source table as Table 1173 Attachment Document. I’ve created a Custom Page because the standard pages calls a function that does not allow me to attach different types of attachment. Thus the Custom page contains SaveAttachment2 function which allows to mention the type of Attachment for the record.

  • Adding Custom methods to Attach the documents with different types on Single Record.
    i.) Export : This function downloads the attachment that is stored in the system wen clicked on the name

ii.) SaveAttachment2:This function saves the attachment for the record with the specific type of attachment. It stores the TableID, Record Primary Key and then LoadType to specify type of attachment for that load.

GetLoadType: This function is used to pass the type

Calling the CustomAttachedPage from the Page/ Table you want to attach.

Output:

From the Record you want to attach the document

To download the Attachment, click on the Attachment FileName.

Conclusion:

In this way we can attach documents to any record of any table in Business Central.


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange