web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Fact box - Document Attachment List Box

(4) ShareShare
ReportReport
Posted on by 163

Hi All,

I Developed One Custom Fact box for an attach document for Custom Table Called Payment memo Header, here Document Attached Successfully but Relevant Document No (PK) is not Update in Document Attachment Table, Kindly Guide me how to Update the Custom Table No into Attachment table,
Pk field No - Memo No. Code [20].

Here my Update My Code 

part(DocumentAttch; "Doc. Attachment List Factbox")
            {
                ApplicationArea = all;
                Caption = 'Advance Payment';
                SubPageLink = "Table ID" = const(Database::"Payment Memo Header"),
                   "No." = field("Memo No_");
            }

 

codeunit 50302 DocumentAttachment
{
    [EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnAfterInitFieldsFromRecRef', '', false, false)]
    local procedure OnafterInit(DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
    var
        FieldRef: FieldRef;
        RecNo: Code[20];
        PaymentMemoHdr: Record "Payment Memo Header";

  begin
        case RecRef.Number of
            database::"Payment Memo Header":
                begin
                    FieldRef := RecRef.Field(1);
                    RecNo := FieldRef.Value;
                    DocumentAttachment.Validate("No.", RecNo);
                end;
        end;

        Message('Document Attach Successfully : %1', DocumentAttachment."No.");

    end;
    [EventSubscriber(ObjectType::Page, Page::"Doc. Attachment List Factbox", 'OnAfterGetRecRefFail', '', false, false)]
    local procedure OnAfterOpenForRecRef(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef);
    var
        Paymentmemo: Record "Payment Memo Header";

  begin
        case DocumentAttachment."Table ID" of
            DATABASE::"Payment Memo Header":
                begin
                    RecRef.Open(DATABASE::"Payment Memo Header");

                    if Paymentmemo.Get(DocumentAttachment."No.") then
                        RecRef.GetTable(Paymentmemo);
                end;
        end;
    end;
}

 

 

Thanks In Advance,

Regards,

Vijay R.

  • Suggested answer
    Yash_Mistry Profile Picture
    648 Super User 2026 Season 2 on at

    Hello @Vijay R ,

    have you tried the event OnAfterTableHasNumberFieldPrimaryKey for the Custom Table attachment? This is the same Process Business Central follows for attachments.

    Below as you can see I've passed the field Id as Field No. so the base application get the Reference for the No. fields value. Also if you have any Line No. primary key they have similar kind of events.

    Hope this Answers your Question. If it was helpful mark this as Verified Answer.

    Thanks,
    Yash Mistry

  • Suggested answer
    Vijay R Profile Picture
    163 on at

    Hi @Yash_Mistry 

        Thank you Yash, It's Working as exptected.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 554 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 344 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 189 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans