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

I want to sent mail to those customer whose balance is greater than 0.

(1) ShareShare
ReportReport
Posted on by 133

Mention below are the code to sent mail i stuck in this code can you please help me to stuck out

Documentation()

OnRun()
SentMailWithTemplate('');

SentMailWithTemplate(CustNo : Code[20])
SMTPSetup.GET;
Customer.RESET;
Customer.CALCFIELDS("Balance (LCY)");
Customer.SETFILTER(Balance,'>%1',0);
IF Customer.FINDSET THEN
Customer.CALCFIELDS("Balance (LCY)");

TemplatesTable.CALCFIELDS(ImportTemp);
IF TemplatesTable.GET('141')THEN
IF Rec.ImportTemp.HASVALUE THEN
CLEAR(Rec.ImportTemp);
Rec.ImportTemp.CREATEINSTREAM(Ins);
StreamReader:=StreamReader.StreamReader(Ins);
EmailTemplateBody:=StreamReader.ReadToEnd();
StreamReader.Close();
NotificationBodyString:=NotificationBodyString.Copy(EmailTemplateBody);
NotificationBodyString := NotificationBodyString.Replace('%SoftwareName%',SoftwareNameTxt);
TextTable:=NotificationBodyString.ToString;
SMTPMail.CreateMessage('',SMTPSetup."User ID",Customer."E-Mail",'Test1','',TRUE);
IF Customer."E-Mail"<>'' THEN
SMTPMail.AddCC(Customer."E-Mail");
SMTPMail.AppendBody(TextTable);
SMTPMail.Send;

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    99,611 Super User 2026 Season 1 on at

    Hi, I think you do not need to do a CALCFIELDS prior to setting a filter on a FlowField.

    For example,

    Hope this helps.

    Thanks.

    ZHU

  • AjayPandey Profile Picture
    133 on at

    Hi ZHU,

    I use that it is working but in the mention code i use html template to sent mail to customer in this code i read blob file and replace all the percentile value and sent mail but it sent blank mai to customer can you plaease check the code why the template is not is sent to customer

    Documentation()

    OnRun()

    SentMailWithTemplate(CustNo : Code[20])

    Customer.RESET;

    Customer.CALCFIELDS("Balance (LCY)");

    Customer.SETFILTER(Balance,'>%1',0);

    IF Customer.FINDSET THEN

     Customer.TESTFIELD("E-Mail");

     TemplatesTable.CALCFIELDS(ImportTemp);

    IF  TemplatesTable.GET('141')THEN

     Rec.CALCFIELDS(ImportTemp);

    IF Rec.ImportTemp.HASVALUE THEN

     Rec.ImportTemp.CREATEINSTREAM(Ins);

     StreamReader:=StreamReader.StreamReader(Ins);

     EmailTemplateBody:=StreamReader.ReadToEnd();

     StreamReader.Close();

     NotificationBodyString:=NotificationBodyString.Copy(EmailTemplateBody);

     NotificationBodyString := NotificationBodyString.Replace('%SoftwareName%',SoftwareNameTxt);

     TextTable:=NotificationBodyString.ToString;

     TextTable:=STRSUBSTNO(TextTable,'%%CustomerName%%',Customer.Name);

     TextTable:=STRSUBSTNO(TextTable,'%%CustomerAddress%%',Customer.Address);

     TextTable:=STRSUBSTNO(TextTable,'%%ContactNo%%',Customer.Contact);

     TextTable:=STRSUBSTNO(TextTable,'%%Date%%',TODAY);

     TextTable:=STRSUBSTNO(TextTable,'%%Email%%',Customer."E-Mail");

     TextTable:=STRSUBSTNO(TextTable,'%Home%','<a href="https:/.../a>');

     TextTable:=STRSUBSTNO(TextTable,'%About%','<a href="https:/.../a>');

     TextTable:=STRSUBSTNO(TextTable,'%ContactUs%','<a href="www.flipkart.com/.../">Contact Us</a>');

     SMTPSetup.GET();

     SMTPMail.CreateMessage('',SMTPSetup."User ID",Customer."E-Mail",'Test1','',TRUE);

    IF Customer."E-Mail"<>'' THEN

     SMTPMail.AddCC(Customer."E-Mail");

     SMTPMail.AppendBody(TextTable);

     SMTPMail.Send;

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,937 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,031 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 700 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans