Document Attachment on Custom Functionality in Business Central #msdyn365BC

Hi Readers,

While working on one of my projects I got a requirement to add Document Attachment base functionality to extension pages.

Let us understand this in detail. The customer was having an extended functionality in Business Central 14, Document Attachment was required to be added in custom Functionality so that the user could store attachments on Custom Functionality.

To achieve this I followed the below-mentioned steps.

Note: This has been achieved in C/AL version, for AL the Logic remains the same.

I have added Part Page in the List Page and Card Page namee “Attached Document” as shown in below screenshot

SubPageLink is set to the Custom Table 50016 and No. is the primary key.

Once you have added this Part page we can see the Attachments on the list page as shown in the below screenshot.

Lets try to test it by adding a Document to the Attachment, so click on the DrillDown of the count and new page will open. Select file and add as shown in below screenshot.

The file is attached in the database , but when we check the Document Count in the part page it is not updated as shown in below screen shot.

To identify the same , we need to Zoom the page and check the Primary Key of the Record . The No. which is getting updated in the record is Blank i.e. The records are inserted in the Table but it is not linked with correct record set.

To achieve this we need to add a subscriber codeunit which will extend the base functionality.

Add 1st Subscriber as shown in below screenshot for OnBeforeDrillDown.

Add below mentioned code to pass the RecordRef.

Add variable in the subscriber for RecorRef.

add 2nd Subscriber as shown in below screenshot for onAfterOpenForRecRef.

Add below mentioned code to pass the RecordRef.

Note: The Field ID for PrimaryKeyFieldID in RecRef.Field(PrimaryKeyFieldID) for my custom table is 3.

Add the Variables as shown below.

We have completed the development part, now lets test the functionality.

When you try to add the attachment now, it will update the Document count as well.

To understand AL Development kindly ref: Customer Requirement for AL Development.

To get new updates and learn about Microsoft Dynamics 365 Business Central Microsoft Learn and Self Learning

Divyesh Chitte

Connect  – Twitter | Facebook | Linkedin 
Follow    – Blog | Facebook Page  | DynamicsCommunity

2 thoughts on “Document Attachment on Custom Functionality in Business Central #msdyn365BC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s