web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Email Notification by a Page Trigger

(0) ShareShare
ReportReport
Posted on by 25

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")

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    I do not think you should put this code in a page trigger.

    You should either have it in a report and schedule the report to be run in a Job Queue once or day or so or in a codeunit that does the same.

    Probably easier to use a processing only report on the data item - then you get the looping for "free".

  • Suggested answer
    YUN ZHU Profile Picture
    103,712 Super User 2026 Season 2 on at

    Hi, I also think that it would be better to put it in an Action (Button), and the Action can be associated with the Codeunit, Report or the function.

    As for your current code is executed in trigger OnValidate(), if you don't manually update "Expiration Date" or execute Rec.OnValidate(), it will not execute.

    Hope this can give you some hints.

    Thanks.

    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 740 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 570 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 291 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans