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; }