Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Suggested answer

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

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 68,757 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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,349 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,212 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans