FromDocumentAttachment.Reset; FromDocumentAttachment.Setrange(FromDocumentAttachment."Table ID", 122); FromDocumentAttachment.SetRange(FromDocumentAttachment."File Type", FromDocumentAttachment."File Type"::Image); if FromDocumentAttachment.FindSet() then begin ToDocumentAttachment.ChangeCompany(SyncCompany.Name); ToDocumentAttachment.Reset; ToDocumentAttachment.Setrange(ToDocumentAttachment."Table ID", 38); if ToDocumentAttachment.FindLast() then LastEntryNo := ToDocumentAttachment.ID else LastEntryNo := 0; repeat LastEntryNo := LastEntryNo + 1; ToDocumentAttachment."Table ID" := 38; ToDocumentAttachment."No." := FromDocumentAttachment."No."; ToDocumentAttachment."Document Type" := ToDocumentAttachment."Document Type"::Invoice; ToDocumentAttachment."Line No." := 0; ToDocumentAttachment.ID := LastEntryNo; ToDocumentAttachment."File Extension" := FromDocumentAttachment."File Extension"; ToDocumentAttachment."File Name" := FromDocumentAttachment."File Name"; case LowerCase(ToDocumentAttachment."File Extension") of 'jpg', 'jpeg', 'bmp', 'png', 'tiff', 'tif', 'gif': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::Image; 'pdf': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::PDF; 'docx', 'doc': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::Word; 'xlsx', 'xls': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::Excel; 'pptx', 'ppt': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::PowerPoint; 'msg': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::Email; 'xml': ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::XML; else ToDocumentAttachment."File Type" := ToDocumentAttachment."File Type"::Other; end; ToDocumentAttachment.User := FromDocumentAttachment.User; ToDocumentAttachment."Document Flow Purchase" := True; TempBlobPurch.CreateOutStream(PurchOutStr); FromDocumentAttachment."Document Reference ID".ExportStream(PurchOutStr); TempBlobPurch.CreateInStream(PurchInStr); CopyStream(PurchOutStr, PurchInStr); ToDocumentAttachment."Document Reference ID".ImportStream(PurchInStr, 'XYZ', FromDocumentAttachment."File Name"); ToDocumentAttachment.INSERT; until FromDocumentAttachment.Next() = 0