mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 22:56:55 +01:00
Add 18 community AL/BC patterns across style, data-modeling, web-services, appsource, breaking-changes, performance, and testing
Contributed by CURABIS ApS, generalized from patterns observed across real AppSource/PTE development. Each article follows the knowledge file format (frontmatter, Description/Best Practice/Anti Pattern, sibling .good.al/.bad.al samples).
This commit is contained in:
parent
07e324ddbc
commit
057e17c202
52 changed files with 1109 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
codeunit 50103 "Order Confirmation Notifier"
|
||||
{
|
||||
procedure Send(FromName: Text; ToAddress: Text; Subject: Text; Body: Text)
|
||||
var
|
||||
Mail: Codeunit Mail;
|
||||
MailSent: Boolean;
|
||||
begin
|
||||
Mail.CreateMessage(FromName, ToAddress, '', Subject, Body, true);
|
||||
MailSent := Mail.Send();
|
||||
if not MailSent then
|
||||
Message(Mail.GetErrorDesc());
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
codeunit 50103 "Order Confirmation Notifier"
|
||||
{
|
||||
procedure Send(ToAddress: Text; Subject: Text; Body: Text)
|
||||
var
|
||||
Email: Codeunit Email;
|
||||
EmailMessage: Codeunit "Email Message";
|
||||
begin
|
||||
EmailMessage.Create(ToAddress, Subject, Body, true);
|
||||
Email.Send(EmailMessage, Enum::"Email Scenario"::Default);
|
||||
end;
|
||||
}
|
||||
28
microsoft/knowledge/breaking-changes/prefer-email-module.md
Normal file
28
microsoft/knowledge/breaking-changes/prefer-email-module.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: breaking-changes
|
||||
keywords: [email, codeunit-mail, email-message, email-scenario, email-account, smtp, sending-email]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Send email through the Email module, not Codeunit Mail (397)
|
||||
|
||||
> Contributions welcome — open a PR to refine or extend this article.
|
||||
|
||||
## Description
|
||||
|
||||
Older AL code sends email by calling `Codeunit Mail (397)`. Business Central's current extensibility model is a different, richer object set — `Codeunit Email`, table `Email Message`, `enum "Email Scenario"`, and the `Email Account`/`Email Connector` interface (Microsoft 365, Current User, SMTP, or a custom connector). New code built on `Codeunit Mail` inherits its SMTP-era, single-connector assumptions and leaves no Sent/Outbox trail behind.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Build on `Codeunit Email` and table `Email Message`. Route the message through an `Email Scenario` so different document types can use different accounts without the calling code needing to know which account that is, and get a tracked Sent/Outbox/Draft record for free.
|
||||
|
||||
See sample: `prefer-email-module.good.al`.
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Calling `Codeunit Mail`'s `CreateMessage`/`Send`/`GetErrorDesc`. It still runs, but it is hard-coupled to whatever SMTP setup exists, and leaves no queryable record of what was sent.
|
||||
|
||||
See sample: `prefer-email-module.bad.al`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue