Did I mention in my last blog post that it is not possible to print reports from extensions?
Well I just remembered that we had the same problem printing from web services in Dynamics NAV 2013 R2.
We got around that by creating a Job Queue Entry for each print job.
This demands three parts:
The Function to start the job could look like this:
SendPrintJob will assemble the report number, the table number to filter and the filter for the primary key.
Then it will call the CreateJobQueueEntry function with the parametres.
CreateJobQueueEntry will create the job queue entry with the parameter needed to filter the report.
The reason it is not a report called directly is that it is only possible to pass a parameter to a codeunit.
The Codeunit to start the report must be a separate codeunit called with the Job Queue Entry table as a parameter.
I know that I have cheated because the primary key here is field 2, but you also have to do some work
You will have to figure the primary key yourself (KeyRef?).
The VarRecRef variable is a variable defined as a Variant. This is a workaround enabling running a report or a page with a RecRef variable as described be Arend-Jan Kauffmann in his blog.
Running my codeunit the test data is rendered like this:
This will create a Job Queue Entry to run the codeunit:
And if the NAS is running then the job queue entry is run and the report is printed.
So no excuse for not printing with extensions