Skip to main content

Notifications

Announcements

No record found.

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
    YUN ZHU 75,595 Super User 2024 Season 2 on at
    RE: How to copy attachments from warehouse receipt to posted warehouse receipt and posted purchase receipt and posted purchase invoice

    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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans