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

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

RTC Report It is not possible to instantiate the Visual Studio bridge.

Hi all, As a Navision developers I have Multiple Versions of Navision running in single Machine. As discussed Earlier in the post how to run multiple Version of RTC in single machine. So my machine have following details for RTC Versions - NAV 2009 R2    - is installed. NAV 2009 SP1  - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 SP1 IN\ NAV 2009         - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 IN\ This approach has been working great for execution of Classic and RTC Clients. However, after installing Dynamics NAV 2009 R2, if i tried to view the Layout for an NAV 2009 SP1 Report i was getting the following error: ---------------------------  Microsoft Dynamics NAV Classic  ---------------------------  It is not possible to instantiate  the Visual Studio bridge.  ---------------------------  OK    --------------------------- After searchi...

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.