I'm trying to save a Salesinvoice
object in CompanyA
Business central as a pdf file in blob storage and afterward save it as a attached document on a purchase order in CompanyB
.
I have made a table which is visible for all company, and I try to save the pdf from CompanyA
in blobfield.
This is my code:
procedure GetSalesOrderDocumentFromHB(var PurchaseHeader: Record "Purchase Header"): Boolean
var
PostedSalesInvoiceNo: Code[20];
inss: InStream;
outss: OutStream;
Parameters: Text;
Blob: record "TableBlob";
begin
PostedSalesInvoiceNo := PurchaseHeader."Vendor Invoice No.";
if PostedSalesInvoiceNo <> '' then
begin
postedSalesInvoice.ChangeCompany('CompanyA');
if postedSalesInvoice.GET(PostedSalesInvoiceNo) then
begin
TempBlob.CreateOutStream(outss);
Blob.INIT;
//Rec.ID := 12;
blob.ID := PostedSalesInvoiceNo;
blob.MyBlob.CREATEOUTSTREAM(outss);
Parameters := StrSubstNo('<?xml version="1.0" standalone="yes"?><ReportParameters name="NN Salgs - Faktura" id="50000"><DataItems><DataItem name="Sales Invoice Header">VERSION(1) SORTING(Field3) WHERE(Field3=1(%1))</DataItem></DataItems></ReportParameters>', PurchaseHeader."Vendor Invoice No.");
Report.SaveAs(50000, Parameters, ReportFormat::Pdf, outss);
CopyStream(outss, inss);
blob.MyBlob.CREATEOUTSTREAM(outss);
Blob.Insert(true);
End;