Skip to main content
Community site session details

Community site session details

Session Id :

Print RDLC report from Classic Client

waldo Profile Picture waldo 6,430

When you read the title, you might want to ask yourself .. why the hell would I want to do that??

Well, the are a number of reasons to do that.. :

  • You want to print to PDF using NAS because you don't know .NET, and you never heared of "Windows Task Schedular";
  • You're upgrading to the RTC and follow the advice of Microsoft to go live role-by-role. So you have a mixed environment. In some occasions, reports are shared between departements, so sometimes a report is printed from RTC, but sometimes, it needs to be printed from classic..
  • You're working mixed mode, have a report for RTC, but want to print that same report from classic client
  • ...

Believe me, there are scenario's, and here I try to deliver you a solution on how to do it..

To print an RDLC report, you have to make sure your code is run on the service tier. There are only two pieces of software that can run on the service tier: RTC and web services. We're NOT working with RTC, so I guess we'll have to use web services, right? And we CAN use web services in the current development environment, so all should be fine.

In fact, Freddy showed us "How to Connect to NAV Web Services from NAV". So I decided to just go from there.

It's not so easy and straight forward to use web services in NAV (.NET Interoperability in R2 sure will help us there...finally :-)), but I must admit .. it only took about 30 minutes to create this little demo.. and that was it. Thanks to Freddy .. again ;°).

Why? Well, the only thing I had to do is create a "save as pdf" routine and publish that as a web service. That routine looks like:

GenerateReport() : Text[250]
ltxtFileName := 'C:\TEMP\';
ltxtFileName += FORMAT(CREATEGUID());
ltxtFileName := DELCHR(ltxtFileName,'=','.');
ltxtFileName += '.pdf';
REPORT.SAVEASPDF(111,ltxtFileName);
EXIT(ltxtFileName);

Not very exciting, is it? Well, it's the idea that counts .. I hope ... . This codeunit, I published as a Web Service:

And then, I started to rebuild Freddy's codeunit to be able to call this web service... . There was not much to rebuild.

  • I deleted to redundant code which would not be used in my services. (I kept (off course) the InvoiceNavWS function .. THAT I need ! :-) )
  • I created an URL and NameSpace to my own web services ..
  • I created a PDFCreateService-function like Freddy's function:

    PDFCreateService(VAR nodeList : Automation "'Microsoft XML, v6.0'.IXMLDOMNodeList") result : Boolean
    result := InvokeNavWS(PDFCreateServiceURL, 'GenerateReport', PDFCreateServiceNS, 'return_value', '', nodeList);

  • Finally, some test-code in the OnRun trigger (supposed to be used as NAS) and I was good to go.

    IF PDFCreateService(nodeList) THEN
    BEGIN
     
    HYPERLINK(nodeList.item(0).text);
    END;

    Or in pseudo: if I succeed running the PDF-routine, then show me my PDF-Document.

So .. hope it's useful. I didn't put any effort in "decent coding". I also want to say that the code is "as is" .. not supported, not fully tested ... you know .. all the Microsoft-official-I-am-not-responsible-mumbo-jumbo ;°) .. just wanted to share the idea ... and the objects, which you can download here.

Enjoy!


This was originally posted here.

Comments

*This post is locked for comments