I am getting the, following error while I am sending a bulk email with attachments (PDF), it is giving an error
The Tenant Media does not exist. Identification fields and values: ID='{00000000-0000-0000-0000-000000000000}'
codeunit 50100 "BGS_Follow Email pattern"
{
Trigger OnRun()
begin
// SendSalesShipment()
end;
var
TempEmailItem: Record "Email Item" temporary;
Rep50000: Report "BGS_Price Email Send -MMBS";
Rep50001: Report "BGS_Price Email Send-Bulk";
etxt: Label ';';
Filename: text;
Kout: InStream;
local procedure "--Version--2.0--"()
begin
end;
procedure SendSalesShipment(mailRec: Record "BGS_Email Notices"; OrderNo: Code[20]; CustNo: Code[20]; srundate: Date): Boolean
var
Customer: Record Customer;
EmailBodyFilePath: Text;
//FileManagement: Codeunit "File Management";
ReportID: Integer;
BodyLayoutCode: Code[20];
emailrec: Record "BGS_Email Notices";
fromDt: Date;
todt: Date;
Email: Codeunit Email;
EmailMessage: Codeunit "Email Message";
AttachmentInStream: InStream;
AttachmentInStream1: InStream;
OutStr: OutStream;
AttachmentTempBlob: Codeunit "Temp Blob";
"Send to": Code[50];
"Send CC": Code[50];
Subject: text[250];
ReadTextChk_lTxt: Text;
begin
if not Customer.Get(mailRec."Customer No") then
exit;
if Customer."E-Mail" = '' then
exit;
//with TempEmailItem do begin
"Send to" := Customer."E-Mail";
"Send CC" := Customer."CC Email" + etxt + Customer."CC Email 2";
Subject := StrSubstNo('Monthly Price Revision %1', mailRec."Customer No");
fromDt := CalcDate('<-1M>', mailRec."Price Date");
fromDt := CalcDate('-CM', CalcDate('<-1M>', mailRec."Price Date"));
emailrec.Reset;
emailrec.SetFilter("Customer No", mailRec."Customer No");
emailrec.SetFilter("Order No", mailRec."Order No");
emailrec.SetRange("Price Date", fromDt, mailRec."Price Date");
// Getting Report Layout
//----------------------
GetReportIDandLayoutCode(ReportID, BodyLayoutCode, emailrec);
Filename := StrSubstNo('Monthly Price Note %1', mailRec."Customer No" + '.PDF');
//Passing Argument to Reports
//--------------------------
Clear(Rep50000);
Rep50000.GetArgs(mailRec."Customer No", OrderNo, fromDt, srundate, '');
// Email Body
//------------------
if emailrec.Segment = 'BULK' then
GenerateShipmentEmailBody(emailrec, 50100, EmailBodyFilePath, BodyLayoutCode, OrderNo, CustNo, srundate)
else
GenerateShipmentEmailBody(emailrec, 50101, EmailBodyFilePath, BodyLayoutCode, OrderNo, CustNo, srundate);
EmailMessage.Create("Send to", Subject, 'Price Notification');
AttachmentTempBlob.CreateInStream(AttachmentInStream);
EmailMessage.AddAttachment(CustNo, 'PDF', AttachmentInStream);
//Nilesh Suggestion while sending email
AttachmentInStream1.ReadText(ReadTextChk_lTxt);
IF ReadTextChk_lTxt <> '' THen
EmailMessage.AddAttachment(CustNo, 'PDF', AttachmentInStream1);
Email.Send(EmailMessage, Enum::"Email Scenario"::"Gas Price Email");
// // Getting Email Body
// //-------------------
// if emailrec.Segment = 'BULK' then
// GenerateShipmentEmailBody(emailrec, 50100, EmailBodyFilePath, BodyLayoutCode, OrderNo, CustNo, srundate)
// else
// GenerateShipmentEmailBody(emailrec, 50101, EmailBodyFilePath, BodyLayoutCode, OrderNo, CustNo, srundate);
end;
//kmk new replacment code
//---------------
local procedure GenerateShipmentEmailBody(DocumentVariant: Record "BGS_Email Notices"; ReportID: Integer; var BodyFilePath: Text; LayoutCode: Code[20]; Korderno: Code[20]; Kcustno: Code[20]; Krundate: Date)
var
// FileManagement: Codeunit "File Management";
ReportLayoutSelection: Record "Report Layout Selection";
bemailrec: Record "BGS_Email Notices";
//---
TempBlob_lRec: Codeunit "Temp Blob";
//---------------
Out: OutStream;
RecRef: RecordRef;
//-----------
TempBlob: Codeunit "Temp Blob";
OutStr: OutStream;
InStrm: InStream;
// RecRef : RecordRef;
Base64EncodedString: Text;
Base64: Codeunit "Base64 Convert";
//--------------
bfromDt: Date;
btodt: Date;
begin
// BodyFilePath := CopyStr(FileManagement.ServerTempFileName('html'), 1, 250);
ReportLayoutSelection.SetTempLayoutSelected(LayoutCode);
bfromDt := CalcDate('<-1M>', Krundate);
Clear(Rep50000);
Rep50000.GetArgs(Kcustno, Korderno, bfromDt, Krundate, '');
bemailrec.Reset;
bemailrec.SetFilter("Customer No", Kcustno);
bemailrec.SetFilter("Order No", Korderno);
bemailrec.SetRange("Price Date", bfromDt, Krundate);
RecRef.GetTable(bemailrec);
// -----
TempBlob.CreateOutStream(OutStr);
// ----
if bemailrec.Segment = 'BULK' then
REPORT.SAVEAS(50101, '', REPORTFORMAT::Pdf, Out, RecRef)
ELSE // save report in TempBlob di recRef
REPORT.SAVEAS(50100, '', REPORTFORMAT::Pdf, Out, RecRef); // FileManagement_lCdu.BLOBExport(TempBlob_lRec, STRSUBSTNO('Proforma_%1.Pdf', bemailrec."Customer No"), TRUE); // export report in PDF format
TempBlob.CreateInStream(InStrm);
//REPORT.SaveAsHtml(ReportID, BodyFilePath, bemailrec);
ReportLayoutSelection.SetTempLayoutSelected('');
end;
local procedure GenerateDocumentEmailAttachment(DocumentVariant: Record "BGS_Email Notices"; ReportID: Integer; zdate: Date; zorder: Code[20]; zcust: Code[20]): Text
var
// FileManagement: Codeunit "File Management";
FilePath: Text;
Zemailrec: Record "BGS_Email Notices";
zfromDt: Date;
Out: OutStream;
RecRef: RecordRef;
//-----------
TempBlob: Codeunit "Temp Blob";
OutStr: OutStream;
InStrm: InStream;
// RecRef : RecordRef;
Base64EncodedString: Text;
Base64: Codeunit "Base64 Convert";
//--test---
Instr2_Chk: InStream;
//-------
//-----------
begin
zfromDt := CalcDate('<-1M>', zdate);
Zemailrec.Reset;
Zemailrec.SetFilter("Customer No", zcust);
Zemailrec.SetFilter("Order No", zorder);
Zemailrec.SetRange("Price Date", zfromDt, zdate);
Zemailrec.findfirst;
RecRef.GetTable(Zemailrec);
//----------------
TempBlob.CreateOutStream(OutStr);
//------
TempBlob.CreateOutStream(OutStr);
Message('Here in Code Unit');
Report.SaveAs(ReportID, '', ReportFormat::Pdf, OutStr, RecRef);
TempBlob.CreateInStream(InStrm);
//---
TempBlob.CREATEINSTREAM(Instr2_Chk);
exit(FilePath);
end;
local procedure GetReportIDandLayoutCode(var ReportID: Integer; var LayoutCode: Code[20]; bulkMMBS: Record "BGS_Email Notices")
var
ReportSelections: Record "Report Selections";
begin
ReportSelections.SetRange(Usage, ReportSelections.Usage::"C.Statement");
if ReportSelections.FindFirst then
if bulkMMBS.Segment = 'BULK' then begin
ReportID := 50101;
LayoutCode := '50000-000001';
end else begin
ReportID := 50100;
LayoutCode := '50000-000003';
end;
// ReportSelections.SETRANGE("Use for Email Body",TRUE);
// IF ReportSelections.FINDFIRST THEN
// LayoutCode := ReportSelections."Email Body Layout Code";
end;
}
-----
Please suggest mistakes..