web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Ax 2012 Print Packing Slip to PDF using X++

(0) ShareShare
ReportReport
Posted on by

Dear Experts,

I have to print posted Packing Slip from Packing slip journal using X++.

From my research, i found the code : 

CustPackingSlipJour custPackingSlipJour;
PackingSlipId packingSlipId;
RecordSortedList list = new RecordSortedList(TableNum(CustPackingSlipJour));
PrintJobSettings printJobSettings;
MenuFunction menuFunction = new MenuFunction(menuitemoutputstr(SalesPackingSlip), MenuItemType::Output);
Args args = new Args();
SalesFormLetter_PackingSlip salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
;
packingSlipId = "DO-0001";

select custPackingSlipJour
where custPackingSlipJour.PackingSlipId == packingSlipId;

list.ins(custPackingSlipJour);

args.object(list);

args.caller(salesFormLetter);

printJobSettings = new PrintJobSettings(salesFormLetter.printerSettingsFormLetter(PrintSetupOriginalCopy::Original));
printJobSettings.setTarget(PrintMedium::File);
printJobSettings.preferredTarget(PrintMedium::File);
printJobSettings.format(PrintFormat::PDF);
printJobSettings.preferredFileFormat(PrintFormat::PDF);
printJobSettings.fileName(@"\\C:\Test\PackingSlip\PackingSlip.pdf");


salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());

menuFunction.run(args);

It works but will only print to screen and not in pdf file.

Does anyone have any suggestion to print Packing Slip to PDF file? 

Thanks in advance.

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    calling reports by menu items has been an old way. when you are using x++ you can make use of controller class. Here you go with x++ code.

    #define.FileExtensionPDF(".pdf")
        str reportFilePath;
    
        SrsReportDataContract       contract;
        SalesPackingSlipContract    rdpContractClass;
        CustPackingSlipJour         tblCustPackingSlipJour;
        
    
        // Create a controller to run the report.
        SrsReportRunController controller = new SrsReportRunController();
    
        // set the report name and design to be run
        controller.parmReportName(ssrsReportStr(SalesPackingSlip, Report));
    
        // suppress the parameter dialog as this is to be run by the batch service
        controller.parmShowDialog(true);
    
        // choose to save the executed report as a pdf file
        /*You can change path to save the report in below lline of codde. It goes as 1st parameter in bellow line*/
        reportFilePath = System.IO.Path::Combine(System.IO.Path::GetTempPath(), ssrsReportStr(SalesPackingSlip, Report) + #FileExtensionPDF);
        controller.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
        controller.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
        controller.parmReportContract().parmPrintSettings().fileName(reportFilePath);
        controller.parmReportContract().parmPrintSettings().overwriteFile(true);
        
        // Set any required parameter values here by first getting the report contract.
        contract = controller.parmReportContract();
    
        // And then fill in that contract based on the contract type (Rdl or Rdp)
    
        // Example of using an Rdp class specific data contract
        rdpContractClass = contract.parmRdpContract() as SalesPackingSlipContract;
    
        // Set the required parameter    
        tblCustPackingSlipJour.clear();
        /*i am always taking firstonly for demo purpose, you can pass needed recid(s)*/
        select firstOnly RecId from tblCustPackingSlipJour;
        rdpContractClass.parmRecordId(tblCustPackingSlipJour.RecId);
    
        // run the report
        controller.runReport();


  • Community Member Profile Picture
    on at

    Dear Sohaib Cheema, 

    Thanks for your reply and solution, but im getting this error : 

    "Variable SalesPackingSlipContract has not been declared." 

  • Suggested answer
    zeeshan.shaikh Profile Picture
    683 on at

    Try using following code to generate report in pdf

       SrsReportRunController          ssrsController = new SrsReportRunController();

       SalesPackingSlipContract        contract = new SalesPackingSlipContract();

       SRSPrintDestinationSettings     printerSettings;

       PackingSlipId packingSlipId;

       custPackingSlipJour custPackingSlipJour;

       System.Exception                e;

       try

       {

    packingSlipId = 'DO-0001';

    select custPackingSlipJour

    where custPackingSlipJour.PackingSlipId == packingSlipId;

       contract.parmRecordId(custPackingSlipJour.RecId);

           ssrsController.parmReportName(ssrsReportStr(SalesPackingSlip, Report));

           ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);

           ssrsController.parmShowDialog(false);

           ssrsController.parmReportContract().parmRdpContract(contract);

           //link the printer settings to the controller

           printerSettings = ssrsController.parmReportContract().parmPrintSettings();

           //print to pdf and always overwrite if the file exists

           printerSettings.printMediumType(SRSPrintMediumType::File);

           printerSettings.fileFormat(SRSReportFileFormat::PDF);

           printerSettings.overwriteFile(true);

           printerSettings.fileName(filename); //Speicfy your file name

           //run & save the report

           ssrsController.runReport();

       }

       catch (Exception::CLRError)

       {

           e = ClrInterop::getLastException();

           while (e)

           {

               info(e.get_Message());

               e = e.get_InnerException();

           }

           info(strFmt("%1",e));

       }

  • Community Member Profile Picture
    on at

    Dear Ali Zeeshan Shaikh,

    Thanks for your reply :)

    But I can't declare "SalesPackingSlipContract".

  • Verified answer
    Community Member Profile Picture
    on at

    I got solution from:

    daxldsoft.blogspot.my/.../print-salesinvoice-packingslip-or.html

    Thanks Experts :)

  • F3D365Report Profile Picture
    10 on at

    I tried the solution from Ali Zeeshan and Sohaib. Report is coming as blank

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans