Monday, May 15, 2017

Microsoft Dynamics NAV 2017 - Email From NAV Part 1.

Hi Readers,

Today I would like to discuss a simple feature that Microsoft is working to be a part of standard NAV or I would say developed a Pattern for, but most of us are still using the old customizing ways which are hard as well as confusing to other developers.

The Pattern in Developed and Enhanced from Microsoft starting NAV 2015. In today's article we will discuss how to use the pattern if we want to send an email from NAV and the in the future article we will discuss other enhancements which can be used instead of customizing NAV.

The idea is Simple - Using base approach and Customize Less, Saves Cost to Customer and hassle for other developers.

Your comments are awaited for future articles.

** This pattern is available from NAV 2015 onwards but for demo, we will be using in NAV 2017.

A new Table and Codeunit have been introduced in NAV for email pattern.
Table       - 9500 - Email Item.
Codeunit - 9520 - Mail Managment.

It take care of most of the things, some of them are listed below -
  1. Raise a Dialog before sending an email. [Optional]
  2. Send Email via Job Queue. [No Errors are shown]
  3. Attach Document.
  4. Add CC & BCC Email ids.
  5. Append a Body in Email Using a Blob.
  6. Check Valid Email Address.
  7. Add Media. 
  8. Plain Text Formatted.
  9. Get Sender Address From - Current User ID, Office 365, SMTP Setup, User Setup, Authentication Email & Active Directory.
I think it might interest you, I am sure these are all the cases that we want to be supported as a customization.

The only feature that I would request to add in this pattern is a possibility to add multiple attachments in an E-mail Item.

Any email that you want to send with max. 1 attachment can be send using this pattern.

So let's see how to use this pattern in code.

Case - My Customer requested to customize NAV for the possibility of sending Report Open Customer Entries using an action on customer page.

Let's Create a Codeunit to send email using the Pattern discussed above -

1. Create a Function which accepts Customer record as a parameter. 

This function check that Email Exist on Customer or not and then generates the record in Email Item.

2. Create Two supported functions which be called from above function.
These functions create Email Body and Email Attachment.

3. Let's Now add action in Customer List / Card which calls this custom codeunit function. 

Now Let's Demo the code - 

If all setup is correct then the system will generate an email as shown below.

Hope it helps.

Let me know if it makes sense there are so many additional features in this pattern that I would like to explain if this article helps my readers.

Waiting for your reply.

You can download the codeunit from OneDrive.

File Name- Microsoft Dynamics NAV 2017  - #SauravNAV_Email_Pattern_V1.0

Let me know your views.

Saurav Dhyani