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

Welcome - Microsoft Dynamics 365!

Hi All, In this article we will discuss the new introduced member of Dynamics Family. Yes you heard it correctly, one more new member with Name "Microsoft Dynamics 365" . #ProjectMadeira   #Dynamics365

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 - 

NAV 2013 Credential Type - How to Use?

Hi all, Please do these activities when you have time, its a long activity and i would suggest do all activities in one go. So be clam and lets start. For NAV 2013 R2 Refer Here. For NAV 2016 Steps have been Reduced Please Refer Here. I have installed NAV 2013 and its work great with my windows credentials. I was checking the service console (Microsoft Dynamics NAV Administration) in NAV 2013 and found out that Credentials Type have multiple Options.