Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

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

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;

  • AjayPandey Profile Picture
    AjayPandey 133 on at
    RE: I want to sent mail to those customer whose balance is greater than 0.

    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;

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,647 Super User 2024 Season 2 on at
    RE: I want to sent mail to those customer whose balance is greater than 0.

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans