How to get a Dynamics NAV report with a Web Service

1. Create a new codeunit. In this scenario we will call this codeunit "CUWebReport" with ID 50000

2. Navigate to "C/AL Globals" and create a function called "GenerateReport"


3. Select "Locals"

4. Select the "Return Value" tab

5. Set "Return Type"=Text and "Length"=100


6. With this completed close "C/AL Locals" window.

7. Now with "C/AL Globals" windows active again. Select "Variables" tab.

8. Create a variable called "filename" with "Data Type"=Text and "Length"=100


9. Now let's add the following code to this codeunit:

filename := 'C:\inetpub\PdfDocuments\';
filename := DELCHR(filename, '=', '{-}');
filename += '.pdf';


10. Save and compile the codeunit.

11. Now it's time to expose this codeunit as Web Service. Navigate to "Administration/IT Administration/General Setup/Web Services"

12. Select codeunit 50000 and give this a service name, we use "Get_PDF_Report"


13. Now it is time to verify that we can see this web service. Open this URL  http://localhost:7047/DynamicsNAV/WS/services.

You should now see this message in your browser, and your Web Service can now be called :


If you don't see this message, you might want to check that  the service "Microsoft Dynamics NAV Business Web Services" has been started.

14. Now it is time to call the Web Service, in this example we use Microsoft Visual Web Developer 2005. And we use the following code to call the Web Service:

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim service As localhost.Get_PDF_Report = New localhost.Get_PDF_Report()
        service.UseDefaultCredentials = True
        service.Url = "
        Response.ContentType = "application/pdf"
        Dim pdfFileName As String = service.GenerateReport()

    End Sub
End Class

But how to consume this Web Service is not in scope for this blog, so we suggest you have look our online help how to consume a Web Service from NAV 2009.

Online help found here:

15. Now also remember to impersonate your web servers application to an appropriate Dynamics NAV user.

16. After compiling a running our project we then get this button in our browser.


17. When activating this button, we get the report specified in Codeunit 50000 displayed as an PDF file in our browser.


Conclusion, now you can give this URL to people who don't have access to Dynamics NAV, and they can execute the report when they see a need for this.


Torben Meyhoff, SDE & Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV

Comments (9)

  1. says:

    "You should now se this message in your browser"

    Little grammar error 😉

  2. navteam says:

    Thanks, Daniele. Fixed. 🙂

  3. David Montejo says:

    Not valid for filtered reports 🙁

  4. says:

    How to Filter the Report ? when Report has multiple Data Items?

    Also how to call Request Form Filters using Web Services.


    Abhay Sharma

  5. says:


    Is it possible to print on printer (and not in pdf) since web service?


  6. Peter says:

    You forget to mention the fact, that users are not allowed to use this without proper license for every named user (granule 1260), that is able to push this button. Unless the button is only for external users and the company has the external connector (granule 2510).

    Or am I misunderstanding something?

  7. Palindrom says:


    I would also very much like to know, whether or not it is possible to print on printer through web service?


  8. Hi,

    In NAV2013 you can print a Report from a Code Unit exposed as Web Service. You would need to call STARTSESSION.

    See the article Printing Reports from a Background Session…/hh997063(v=nav.70).aspx



  9. Chris Jones says:

    So frustrating you need Dev licence for something that is so easy to implement!

Skip to main content