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.. :
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 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.
PDFCreateService(VAR nodeList : Automation "'Microsoft XML, v6.0'.IXMLDOMNodeList") result : Boolean result := InvokeNavWS(PDFCreateServiceURL, 'GenerateReport', PDFCreateServiceNS, 'return_value', '', nodeList);
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.
The Webservice is running on the service tier .. which means it's going to save on the NAV Server as well. This is normal behaviour which you have to manage (save it to a network folder and hyperlink that, for example).. .
I believe I have the same issue as Luna.
On the client (not the NAV app server) where I run the CDU, I get an error message "C/SIDE Hyperlinking failed", it then gives me the path to the PDF, except the PDF has now been created but on the NAV server. Not the client!
How do I fix this?
Another question: how can I set the report to run as a variable so I can use it multiple times for different reports?
Seems you're having installation issues – delegation/SPN not correctly installed.
Or isn't it a security issue?
as the webservice is Always going to produce the PDF .. it shouldn't be any different running on either the local machine or not :-/
If I run this on same machine as the webservice it works great but if I run it from a client machine service tier seems to struggle with the creating the PDF. Any ideas?