clearing the Mail Variables for CodeUnit 397

stormcandi
Member Posts: 27
I am new to this forum and to Microsoft NAV development. I am hoping someone can shed some light on this for me. I have a query that I am reading to get data for an email. Right before I loop to the next record I send the email. The issue I'm having is that the Email Body is not clearing out when it goes through the loop again. So it appends all the next record's data to the first record. I thought once you iterate through a record and go to the next record, that all variables are automatically cleared. I am pasting my code below. Hopefully someone can tell me what I am doing wrong.
](*,)
CompanyInfo.GET(); PaymentList.SETRANGE(Posting_Date, StartDate); IF NOT PaymentList.OPEN THEN EXIT; WHILE PaymentList.READ DO BEGIN Body := ''; EmailTo := email address here; EmailCC := 'email address here'; Subject := 'Test Email'; Mail.AddBodyline(STRSUBSTNO('<table><tr><td>%1</td></tr></table>', PaymentList.Name)); Mail.AddBodyline('Dear Customer,'); Mail.AddBodyline('<br><br>'); Mail.AddBodyline('The below payment has been received:'); Mail.AddBodyline('<table cellpadding="5" cellspacing="5"><tr><th>Posting Date</th><th>Amount</th></tr>'); Mail.AddBodyline(STRSUBSTNO('<tr><td>%1</td><td>$%2</td></tr>', PaymentList.Posting_Date, FORMAT(PaymentList.Amount, 0, '<Precision,2:2><Standard Format,0>'))); Mail.AddBodyline('</table>'); InvoiceList.SETFILTER(Document_No, PaymentList.Document_No); InvoiceList.SETFILTER(Vendor_No, PaymentList.Vendor_No); IF NOT InvoiceList.OPEN THEN EXIT; Mail.AddBodyline('This payment was applied to the below invoice(s):'); Mail.AddBodyline('<table cellspacing="5" cellpadding="5"><tr><th>Posting Date</th><th>Amount</th></tr>'); WHILE InvoiceList.READ DO BEGIN Mail.AddBodyline(STRSUBSTNO('<tr><td>%1</td><td>$%2</td></tr>', InvoiceList.Posting_Date, FORMAT(InvoiceList.Amount, 0, '<Precision,2:2><Standard Format,0>'))); END; Mail.AddBodyline('</table>'); InvoiceList.CLOSE; Mail.AddBodyline('<br>'); Mail.AddBodyline('Regards,'); Mail.AddBodyline('<br><br>'); Mail.AddBodyline(CompanyInfo.Name); Mail.NewMessage(EmailTo,EmailCC,Subject,Body,'',FALSE); CLEARALL; END; PaymentList.CLOSE;
](*,)
0
Answers
-
Hi Stormcandi,
apparently, your CLEARALL, in combination with the WHILE ...READ loop, doesn't do the job.
So you have to consider other options:
- program a REPEAT..UNTIL and use CLEAR(Mail);
- create and call a function everytime you read a new rocord, programm the mail-functionality there, and create the variable Mail as a local variable
Ernsthttp://www.vssolutions NAV-Outlook synchronisation re-invented.0 -
I took part of your suggestion and it worked. Instead of CLEARALL I did Clear(Mail). I never tried the Clear(Mail) and didn't even think about it. Worked like a charm. Thanks so much for your help!
\:D/0 -
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions