NAV2009: Use SAVEASPDF in classic client


Hallo zusammen!

Nachstehender Post ist deswegen mal wieder englisch weil der Originalcontent englisch ist 😉 – Viel Spass damit


Book Microsoft Dynamics NAV 2009 Inside:

Using SAVEASPDF in classic client

In this sub chapter I will explain a new C/AL built-in function to save reports as PDF. When I discuss about this feature every time I got the same question:

“Is it possible to use SAVEASPDF also in the NAV classic client?

Well, at a first glance we have to say “No”, but in a second I will show you that it is possible to save reports as PDF from classic client using the DynamicsNAV://// command.

This is also the reason why I didn’t explain the default built-in function SAVEASPDF like it is described in the default online help of the Microsoft Dynamics NAV 2009. I want to show „more“ than this, and as I mentioned, we are building a solution for using the function in the classic client.

Note: This means there is no effect when using the function in the classic client during user run-time.We are using a workaround for SAVEASPDF directly from the classic client.

Our goal is to add a new command button to Form 132 Posted Sales Invoice and name it Print PDF.


Before we start you should know that the concept isn’t “best practice” for using it by every customer in this way. One reason for this is, that you need 2 sessions at runtime for this solution. But less or more it should show that it is possible, and perhaps in some situation it could be helpful.:-)

What we need is to understand how it will work. The function SAVEASPDF is only working in Role Tailored client. The only way is to pass the current record from classic client to the Role Tailored client and execute SAVEASPDF. Is it useful running the classic client and then starting the RT client?


I think in some scenarios it could be.

You need

– an appropriate Codeunit for encode the current record key to the role tailored client

– a page for pass the current record to the appropriate page and start SAVEASPDF

Codeunit Sales Invoice PDF

Earlier in this chapter(book) we discussed and used the Drill-Through functionality in reports, to navigate from a report directly to a page.

Note: Although we used the RECORDID from the Record Ref variable, and the new values 0 and 10 with the FORMAT function to get the RECORDID in a way that the Role Tailored client can use it.

For developing SAVEASPDF from classic client, we also need the RECORDID to run a page with the specific sales invoice. The problem is that using the FORMAT function with the parameter value 10 in classic client, isn’t supported. (It doesn’t effect anything)

For this reason we built a Codeunit which offers the same functionality for the classic client. Because the Codeunit takes some time you can download it here

Codeunit: Sales Invoice PDF 50100



User defined function which returns likely the same value like the default built-in function in NAV 2009

Function: ConvertASCIICode2Binary

User defined function for calculate the binary value of ASCII characters (integer)

Function: GetBase64Character

User defined function to return the appropriate base64 encoded character of a ASCII character

Function: SetLengthChr

User defined function to add an additional base64 character set to the string because NAV 2009 starts the RECORDID string with the length of the translating string

Note: This Codeunit can be used to encode an ASCII string to a base64 string. This Codeunit offers some features more which are only used by Microsoft Dynamics NAV 2009.

Perhaps you are confused now.:-)? Here a small example:

Table 112, the primary key is field “No.”, and if you are calling the RECORDID function for the record 103001 in the classic client it returns:

Classic client: “Sales Invoice Header: 103001”

For the role tailored client it returns:

RT client: “224;cAAAAACJBjEwMzAwMQ==“

At the latest now, you can remember about starting a page which a specific record (from a report). This is what we need directly from the classic client.

It’s not that important what the string contains, but here are some examples how to rebuilt the logic.

“224;cAAAAACJBjEwMzAwMQ==“ = the Sales Invoice number and the length of the string base64 coded

Note: 103001 in this example

“224;cAAAAACJBjEwMzAwMQ==“= ASCII character 112

Note: 112 is the table id of this example!

Before going on with this lab please download the Codeunit and import it into Microsoft Dynamics NAV 2009!

Page Sales Invoice PDF

Why do we need a page?

In the current version it isn’t possible to pass a RECORDID or similar parameter directly to a report in the RT client. For this we are using a page passing the right record, and print the report directly from the page.

The page is very simple:

1. Choose in the menu Tools – Object Designer – Page

2. Click on the button New (right, below)

3. Enter table 112 Sales Invoice Header

4. Select create a blank page of type Card

5. Enter Sales Invoice PDF for the Container – ContentArea


Before we are writing 3 lines of C/AL code we add some additional information that it looks like a “printing dialog”. 🙂

6. Enter a new line of type Group and call it “Printing page…

7. Enter another new line of type FieldSource Expr “No.” and call it “send to PDF – invoice no.


Change to the OnAfterGetRecord trigger. In my example we are using the C:\ directory and the invoice no. for saving the PDF.

8. Enter the following lines of C/AL code into OnAfterGetRecord

SETRANGE(“No.”,”No.” ) – it isn’t possible to change the record

REPORT.SAVEASPDF(206,’C:\’+”No.”+’.pdf’,Rec) – start the report and pass the record

HYPERLINK(’C:\’+”No.”+’.pdf’ ) – open the PDF

Figure 4.107 OnAfterGetRecord


9. Save and close the page

Note: There are no C/AL Globals required

Finish the customization – change the Posted Sales Invoice form 132

Now add a new button on form 132 to finish the customization.

1. Choose in the menu Tools – Object Designer – Form

2. Navigate to form 132 and click Design

3. Copy and paste the Navigate button

4. Change the caption of the copy to Print PDF


5. Place the button where you want (perhaps on the Help button)

6. Select the button and press F9 to open C/AL editor

Note: if there are already some lines of C/AL code in the OnPush trigger, delete it.

7. Select View – C/AL Globals to open the global variable window

8. Enter a new variabledata type: Codeunitsubtype:Sales Invoice PDFname: SalesInvPDF

9. Close the C/AL Globals window

10. Enter SalesInvPDF.RUN(Rec) into the OnPush trigger of the button

11. Save and close the form


Note: There are many ways to integrate the Codeunit with other scenarios: for example menu buttons or tables like Posted Sales Shipment.


Start and run the solution

Now we are finished with integrate SAVEASPDF directly into the classic client.

1. Start Posted Invoices from the Navigation Pane

2. Select an invoice of your choice and click Print PDF (see figures below)

Note: Try some other situation and changes with the Codeunit and implementing. I am sure you will find some good samples to use it, like after a technical upgrade.


Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.