Skip to main content

How To Report SaveAsHTML Pre NAV 2017.

Hi Readers,

Origin of the today's post is a requirement to Save as Report as HTML in NAV 2016. This also brings some learnings for me so thought to share with you all.

Till NAV 2009 (if I remember it correctly) Report.SaveAsHTML was supported but due to design changes in NAV Microsoft decided to obsolete this feature after NAV 2009. But later in NAV 2017, microsoft felt a need to the function and it came back in existence.

But due to this confusion, I have provided a bad estimate and end-up spending good amount of time to translate a report (in my case word layout) to an HTML file.

In this article, we will see how we can transform a word file to an HTML File using DOTNET Components.



** This article applies to NAV 2013, NAV 2013 R2, NAV 2015 and NAV 2016 as SaveasHTML exist in NAV 2017.

** Code in the article is to save HTML file as user defined location in the client. If you need to save in server, change DOTNET variable of RunOnClient = NO and set file path and Name instead of a popup.

For the demo, i will be using a SaveasWord Feature to make it simple but you can also use word layout with same code base in your need.

I am planning to keep all DOTNET re-writes in the same Codeunit that it can be used whenever required.

Create a New Function - SaveReportAsHTML which input a Variant Record that needs to be printed.
The Function Creates -

1. Two Temp files of Word and HTML extensions to be used in the process later.
2. Get Report ID using Report selection & Save Report as Word.
3. Open Word File using DOTNET, Save as HTML and Save File in Temp Path.
4. Ask User for File Path and Move File from Temp to the User Defined Path.

Dotnet Variables used in function -

WordApplication - Microsoft.Office.Interop.Word.ApplicationClass.'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

WordDocument - Microsoft.Office.Interop.Word.Document.'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

WordHelper - Microsoft.Dynamics.Nav.Integration.Office.Word.WordHelper.'Microsoft.Dynamics.Nav.Integration.Office, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

WordSaveFormat - Microsoft.Office.Interop.Word.WdSaveFormat.'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

All Code used for these four tasks is below.


* You can extend Part two (Case Statement) as per your requirement. Report Code will remain same.

Almost Done. Let's do calling from Sales Invoice Page.

Add an action in Page and Call the function that we wrote above, as shown below.


Let's Run.


Share your thoughts about it. I have so many rewrites where I use Dotnet to get performance or only option to rewrite in new versions. If you have a scenario that we can discuss in future articles please put also that as the comment.

If you want to use the code, please download an object from the on-drive.
File Name - Microsoft Dynamics NAV -#SauravNav_Dotnet_Functions_Codeunit_50000

Please share your views. Happy to hear all of them !! Stay connected will be back soon.

Regards,
Saurav Dhyani
www.sauravdhyani.com

Comments

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.