We came across an issue reported to us where they were trying to automate printing of reports as PDF files using batch processing on the server. Printing reports directly worked fine and they were able to save the PDF files it generated successfully on the file system, but it only failed when using Batch.

The issue occurred because the server had not been configured to allow printing on the server. For reference here is the snippet of code that was being run to print the report on the server:

   reportRun = new reportRun(args);
   reportRun.query().interactive(False);
   reportRun.report().interactive(False);
   reportRun.setTarget(printMedium::File);
   reportRun.printJobSettings().setTarget(PrintMedium::File);
   reportRun.printJobSettings().preferredTarget(PrintMedium::File);
   reportRun.printJobSettings().format(PrintFormat::PDF);
   reportRun.printJobSettings().warnIfFileExists(False);
   reportRun.printJobSettings().suppressScalingMessage(True);
   reportRun.printJobSettings().packPrintJobSettings();
   reportRun.printJobSettings().fileName(filename);
   reportRun.run();

Although you are not physically printing a report to a printer and saving it to file instead, the print x++ api’s that are used require the same privileges as though you are printing to a printer on the server.

The issue was resolved by following the steps given in article Microsoft Dynamics AX reports under the section titled Enable users to print reports from the server.