Hi,
I have created a certification page in our Business Central Version 21, wherein it serves as monitoring of those expiring company certificates that we have. The page contains the column for Validity of the certificate in months and the email addresses of the concerned personnel to renew the certificate. I want to send an automatic email notification to the email addresses in my certification page if the validity in months equals to 1. I have tried coding it, but it seems not to work. Below are what I have a;ready started. I have global variables for BodyMessage, AddBodyMessage & Recipients. How can I simplify this? Hoping for your kind help. Thank you in advance.
field("Expiration Date"; "Expiration Date")
{
ApplicationArea = All;
trigger OnValidate()
var
myInt: Integer;
Email: Codeunit Email;
EmailMessage: Codeunit "Email Message";
Vendor: Record Vendor;
UserSetup: Record "User Setup";
recipient: Text;
begin
if "Expiration Date" = 0D then
"Validity in Months" := 0 else
"Validity in Months" := DATE2DMY("Expiration Date", 2) - DATE2DMY(TODAY, 2) + 12 * (DATE2DMY("Expiration Date", 3) - DATE2DMY(TODAY, 3));
if "Validity in Months" = 1 then begin
Clear(BodyMessage);
Clear(AddBodyMessage);
Clear(Recipients);
Recipients.Add(rec."Notification Email");
BodyMessage := 'Dear Trade Partner, <br> <br> Your <strong>E%1</strong> is about to expire in one month, kindly arrange the renewal of your certificate. Thank you.';
BodyMessage += '<br><br><hr> This is a system generated email. Please do not reply to this mail.</hr>';
AddBodyMessage := StrSubstNo(BodyMessage, rec."Certification Type");
EmailMessage.Create(Recipients, 'Vendor Certificate Expiry', AddBodyMessage, true);
EmailSend.Send(EmailMessage, Enum::"Email Scenario"::Default);
end;
end;
}
field("Validity in Months"; "Validity in Months")
{
ApplicationArea = All;
}
field("Notification Email"; "Notification Email")