web
You’re offline. This is a read only version of the page.
close
Skip to main content
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")

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at
    RE: Email Notification by a Page Trigger

    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
    95,307 Super User 2025 Season 2 on at
    RE: Email Notification by a Page Trigger

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans