Pass Document Attachment from Company A to Company B

julkifli33julkifli33 Member Posts: 1,060
edited 2023-02-04 in NAV Three Tier
Hi All,
I am using cloud BC.

any idea how to pass Document attachment from Company A to Company B?
so I have Posted Purchase in Company A, i want to pass all these records to Unposted Purchase Invoice in Company B.
Purchase Header and Purchase Line no problem.
the thing is how about Document Attachment.


My Code :
    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

it is inserted to the Company B as attachment.
but attachment is all 0 KB.
7kjovrsafvgd.png

Do i miss something?
Sign In or Register to comment.