Dear Experts,
I write the code when Purchase order will release then Purchase Order will go to the concern person as well as vendors.
Now I have added the new fields in "Purchase header" table name is "Pre-Approved invoice" it is a boolean type fields.
Now the concern is if checkbox is checked then no mail will float. If checkbox is unchecked...then mail go the concern person.
My written code is below:
SendMailtoVendor(PurchHeader : Record "Purchase Header")
IF PurchHeader."Currency Code"='' THEN
PurchHeader."Currency Code" := 'INR';
PH.RESET;
PH.SETRANGE("Document Type",PurchHeader."Document Type");
PH.SETRANGE("No.",PurchHeader."No.");
// PH.SETRANGE(PH."Pre-Approved Invoice", FALSE);
PH.FINDFIRST;
DomPO.USEREQUESTPAGE(FALSE);
DomPO.SETTABLEVIEW(PH);
PdfDocPath :='Purchase Order Details-'+PurchHeader."No."+'.pdf'; //FileName
Path := 'E:\PO Mails\'+PdfDocPath; // Directory + Path
IF RecUserID.GET(PurchHeader."Created by ID") THEN;
IF NOT DomPO.SAVEASPDF(Path) THEN
ERROR('PDF Creating Failed!\\ERROR:\\' + GETLASTERRORTEXT);
SmtpMail.CreateMessage('MKU Limited',RecUserID."E-Mail",'','Released PO No.: '+ PurchHeader."No.",'',TRUE);
IF RecUserID.GET(PurchHeader."Created by ID") THEN
SmtpMail.AddCC(RecUserID."E-Mail");
RecVend.GET(PurchHeader."Buy-from Vendor No.");
//IF PurchHeader."Mail Sent to Vendor" =FALSE THEN BEGIN
IF CONFIRM(Text001+RecVend."E-Mail") THEN
SmtpMail.AddRecipients(RecVend."E-Mail");
//END;
SmtpMail.AppendBody('Dear Sir / Madam,');
SmtpMail.AppendBody('<br><br>');
SmtpMail.AppendBody('Please find attached the Purchase Order for the following items -');
SmtpMail.AppendBody('<br><br>');
SmtpMail.AppendBody('<table border="1">');
SmtpMail.AppendBody('<tr>');
SmtpMail.AppendBody('<th align="left" colspan="1">Vendor Name</th><th colspan="5">'+PurchHeader."Buy-from Vendor Name"+'</th>');
SmtpMail.AppendBody('</tr>');
SmtpMail.AppendBody('<tr>');
SmtpMail.AppendBody('<th align="left">Item Description</th>');
SmtpMail.AppendBody('<th>Currency</th>');
SmtpMail.AppendBody('<th>UOM</th>');
SmtpMail.AppendBody('<th>Quantity</th>');
SmtpMail.AppendBody('<th>Rate</th>');
SmtpMail.AppendBody('<th>Due Date</th>');
SmtpMail.AppendBody('</tr>');
//ReqLine.SETRANGE(ReqLine."Indent No.", "Indent No."); /////////////////// with u can see the mail documnent wise.
PurchLine.RESET;
PurchLine.SETRANGE(PurchLine."Document Type",PurchHeader."Document Type");
PurchLine.SETRANGE("Document No.",PurchHeader."No.");
IF PurchLine.FINDSET THEN
REPEAT
SmtpMail.AppendBody('<tr>');
SmtpMail.AppendBody('<td align="left">'+FORMAT(PurchLine."Print Description")+'</td>');
SmtpMail.AppendBody('<td align="center">'+PurchHeader."Currency Code"+'</td>');
SmtpMail.AppendBody('<td align="center">'+FORMAT(PurchLine."Unit of Measure Code")+'</td>');
SmtpMail.AppendBody('<td align="right">'+FORMAT(PurchLine.Quantity)+'</td>');
SmtpMail.AppendBody('<td align="right">'+FORMAT(PurchLine."Direct Unit Cost")+'</td>');
SmtpMail.AppendBody('<td align="center">'+FORMAT(PurchLine."Promised Receipt Date")+'</td>');
SmtpMail.AppendBody('</tr>');
UNTIL(PurchLine.NEXT=0);
SmtpMail.AppendBody('</table>');
//SmtpMail.AppendBody('<br>');
//SmtpMail.AppendBody(' If you have any queries , please mail at preeti.bhatia@mku.com OR vashique.ahmed@mku.com');
SmtpMail.AppendBody('<br><br>');
SmtpMail.AppendBody('<b>This is a system approved order so does not require signature.</b>');
SmtpMail.AppendBody('<br><br>');
SmtpMail.AppendBody('<b>Regards</b>');
SmtpMail.AppendBody('<br>');
SmtpMail.AppendBody('MKU Limited (Purchase Department) ');
SmtpMail.AddAttachment(Path,PdfDocPath);;
GetReportFilters(SmtpMail,PurchHeader."Shortcut Dimension 1 Code",'MR-0012',5722,RecItem."Item Category Code");
GetReportFilters(SmtpMail,'','MR-0012',91,'');
GetReportFilters(SmtpMail,'*'+PurchHeader."Shortcut Dimension 1 Code"+'*','MR-0012',91,'');
SmtpMail.Send;
For sending the mail I have write the code in codeunit no 415...
the screenshot is below:
![]()