Skip to main content

Microsoft Dynamics NAV 2017 - Email From NAV Part 3.

Hi Readers,

Let's continue what we are discussing from Last two weeks.

To understand the content of this article and use the pattern we are about to discuss in this article you need to go through old articles.

If you haven't read the Part 1 and Part 2 below are the links for same.

Part 1 - Send Email from Navision using a Pattern provided by Microsoft in New version.

Part 2 - Develop a Word Layout for Sales Shipment Report.

In this last article, we will discuss how to use the Pattern & Word Layout for sending an Email.

The idea is Simple - Using word Layout for the Email Body and then use Email Pattern to send Email.

Without Further Delay, let's discuss how we can configure & customize same in NAV 2017.
Thanks to Mohamed Zayed and hope this solves your issue.

** What we are customizing is already part of standard NAV. The article is just for an explanation how to customize if required to be added in some other NAV areas.

1. As we discussed in Part 2 we can have multiple word layout for the same report. These Layouts can be used for other usages than sending the email. So somewhere we need to setup which of the multiple layouts should be used for Emailing from NAV.

Microsoft Have added word layout selection in Report Selections. As shown below I will select the word layout that we created in Last Post.


2. Now Let's add some code for the new pattern that we want to use. New Function Name is SendSalesShipment which accept the record and returns Email is Sent or Not.

Functions Do Pre-Check, we can add more if required. After that, it uses the same Pattern as in Article 1.
While using pattern we use three Functions, shown below -
a.  Get Report ID and Word Layout Code to be used.
b.  Generate Email Attachment as PDF.
c.   Generate Email Body.

After Doing all this, Function sends an email and return if the email is sent.


3. So What these functions Do?

a. GetReportIDandLayoutCode - 
    This Function looks up of Report Selection table for the Shipment Report and get the report id and also the Layout code. 

b. GenerateDocumentEmailAttachment - 
     This function creates a new pdf file, and use SAVEASPDF using the Report ID from the first function and then exit the File Path for attachment. 

c. GenerateShipmentEmailBody - 
    This function creates a new temp HTML file. select the word layout and use SAVEASHTML to save word layout file. The word layout file path is sent back to the pattern function which is used to pass to the Body File Path.


4. Add a function in Sales Shipment Page for Sending Email.


5. Here is the Email that is sent from NAV.



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_V2.0

Let me know your views.

Regards,
Saurav Dhyani

Comments

  1. Hi Saurav,

    The email in outlook shows html tags. How can I remove them?

    Thanks,
    Umair

    ReplyDelete
    Replies
    1. Umair,
      Are you using a custom Email Template developed by you. I think its a problem in coding that.
      It works great when i use it in custom also.

      Delete
  2. Hi Saurav,
    Interesting topic.
    Unfortunately links to Part 1 and 2 is not working.
    Also I do have a question. If Client wants to use plain text previously stored as a BLOB for the e-mail body instead of predefined Layout, could you advice nice and elegant way how to do it. The plain text also contains placeholders, that must be populated with values before sending e-mail.

    ReplyDelete
    Replies
    1. Part 1 and 2 are working now.
      Yes its possible, but I will have to setup a NAV 2017 environment. You can store it in blob, then extract and convert placeholders to value.

      Delete

Post a Comment

Popular posts from this blog

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

MSDYN365BC - Data Upgrade To Microsoft Dynamics 365 Business Central on premises.

Hi Readers, We have already talked about the number of steps for upgrading to Business Central on Premises from different NAV versions. After that article, I received multiple requests for an article which list down steps for Data Migration. In this article, we will discuss steps of data migration to MSDYN365BC (on-Prem) from NAV 2017. For this article, I am considering a Cronus Demo Database without any customization. For an actual upgrade project, we will have to complete object merge using compare and Merge process. After the Merge Process, the next step is data migration. Let's discuss those steps. Direct Upgrade to Microsoft Dynamics 365 Business Central (on-Prem) is from following versions - 1. NAV 2015. 2. NAV 2016. 3. NAV 2017. 4. NAV 2018.