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...
Suggested Answer

How to copy attachments from warehouse receipt to posted warehouse receipt and posted purchase receipt and posted purchase invoice

(1) ShareShare
ReportReport
Posted on by 4

How to copy attachments from warehouse receipt to posted warehouse receipt and posted purchase receipt and posted purchase invoice?

I have created part in warehouse receipt and posted whse receipt and posted purchase receipt as below.

        part("Attached Documents"; "Document Attachment Factbox")
            {
                ApplicationArea = All;
                Caption = 'Attachments';
                Editable = false;
                SubPageLink = "Table ID" = const(Database::"Posted Whse. Receipt Header"), "No." = field("No.");
            }

I have used the below subscriber to copy the attachments from warehouse receipt to posted warehouse receipt but only document count is flowing but the documents are not copied. May I know why they are not inserted?

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Post Receipt", 'OnAfterPostedWhseRcptHeaderInsert', '', false, false)]
    local procedure OnAfterPostedWhseRcptHeaderInsert(var PostedWhseReceiptHeader: Record "Posted Whse. Receipt Header"; WarehouseReceiptHeader: Record "Warehouse Receipt Header");
    var
        DocAttmtMgmt: Codeunit "Document Attachment Mgmt";
        DocExists: Boolean;
        FromRecRef: RecordRef;
        ToRecRef: RecordRef;
        FromDocumentAttachment: Record "Document Attachment";
        ToDocumentAttachment: Record "Document Attachment";
        FromFieldRef: FieldRef;
        ToFieldRef: FieldRef;
        FromNo: Code[20];
        ToNo: Code[20];
        ToDocumentType: Enum "Incoming Document Type";
        ToLineNo: Integer;
    begin
        FromRecRef.Get(WarehouseReceiptHeader.RecordId);
        ToRecRef.Get(PostedWhseReceiptHeader.RecordId);
        DocExists := DocAttmtMgmt.AttachedDocumentsExist(FromRecRef);
        if (DocExists = true) then begin
          
            FromDocumentAttachment.SetRange("Table ID", FromRecRef.Number);
            case FromRecRef.Number() of
                DATABASE::"Warehouse Receipt Header":
                    begin
                        FromFieldRef := FromRecRef.Field(1);
                        FromNo := FromFieldRef.Value();
                        FromDocumentAttachment.SetRange("No.", FromNo);
                    end;
            end;

            if FromDocumentAttachment.FindSet() then
                repeat
                    Clear(ToDocumentAttachment);
                    ToDocumentAttachment.Init();
                    ToDocumentAttachment.TransferFields(FromDocumentAttachment);
                    ToDocumentAttachment.Validate("Table ID", ToRecRef.Number);

                    case ToRecRef.Number() of
                        DATABASE::"Posted Whse. Receipt Header":
                            begin
                                ToFieldRef := ToRecRef.Field(1);
                                ToNo := ToFieldRef.Value();
                                ToDocumentAttachment.Validate("No.", ToNo);
                            end;

                    end;
                    
                   ToDocumentAttachment.Insert(true);

                until FromDocumentAttachment.Next() = 0;
        end;
    end;
}

  • Suggested answer
    YUN ZHU Profile Picture
    104,146 Super User 2026 Season 2 on at

    Hi, just simply made an example of copy attachments from Warehouse Receipt to Posted Warehouse Receipt, hoping to give you some hints.

    https://yzhums.com/37986/

    Thanks.

    ZHU

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 671 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 434 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 241 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans