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)

How to print ssrs report from X++

(0) ShareShare
ReportReport
Posted on by

Hi I have writen code for to print to pdf so i am stuck in printing to printer directly here is the code i have written

private void addToQueue(container _licensePlates)
{
int conLength, cnt;
WHSLicensePlateParent licensePlateID;
WHSWorkMHUSummary_env wHSWorkMHUSummary_buffer;
SrsReportRunController controller;
SRSPrintDestinationSettings settings;
str filePath = @'C:\MHUSummary';
str fileNameWithoutExt;
#File

conLength = conLen(_licensePlates);

for(cnt = 1; cnt <= conLength; cnt++)
{
delete_from wHSWorkMHUSummary_buffer;
controller = new SrsReportRunController();

licensePlateID = conPeek(_licensePlates, cnt);
// call the report for this context license plate
// step 1 - create records in WHSWorkMHUSummary_env table
if(licensePlateID)
{
this.insertReportTable(licensePlateID);
/*
wHSWorkMHUSummary_buffer.LicensePlateId = licensePlateID;
wHSWorkMHUSummary_buffer.Description = "Test" + int2str(cnt);
wHSWorkMHUSummary_buffer.insert();
*/

controller.parmReportName(ssrsReportStr(WHSMHUSummaryReport_env, Report));
controller.parmShowDialog(false);
controller.parmLoadFromSysLastValue(false);

settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
//fileNameWithoutExt = int2str(cnt);
fileNameWithoutExt = licensePlateID;
settings.fileName(filePath + #FilePathDelimiter + fileNameWithoutExt + 'pdf');

controller.startOperation();
}
controller = null;
}
}

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    If you want to print a report to printer, use SRSPrintMediumType::Printer.

    SRSPrintMediumType::File prints to file, not to printer.

  • Community Member Profile Picture
    on at

    I did the same what you said it's hanging up ax so I think it's not working for that code can you check whether I need to change the code

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    When you say it hangs, what processes can you see on SQL Server? You can run the sp_axwho stored procedure on your AX database to check running statements, maybe it is trying to gather your data?

    Take a look on where does it "hang" if you try to debug the process. If you run it in IL or in a batch, make sure you try to debug it using Visual Studio, where you attach the debugger to the AX AOS process in a Dev/Test environment.

    Maybe your loop is wrong, we cannot test your code since you have custom methods in there like insertReportTable. I am afraid you need to troubleshoot this using the tools provided by AX for resolving such issues.

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    I'm pretty sure that printing to printer is possible in AX, so it's more likely the problem is in your code.

    If you forgot to set the medium, there is a chance that you forgot other parameters as well. For example, are you setting a printer name of file format and file name?

    if needed, show us your updated code. Also try removing pieces of code not related to your question.

  • Suggested answer
    Pravasti AK Profile Picture
    2,985 on at

    Hi Chay,

    Here is the working code for me,

    static void JobSendToPDFInvoice(Args _args)

    {

       SrsReportRunController          controller = new SrsReportRunController();

       SRSPrintDestinationSettings     settings;

       CustInvoiceJour                 custInvoiceJour = CustInvoiceJour::findRecId(xxxxxxxxxx);

       SalesInvoiceContract            salesInvoiceContract = new SalesInvoiceContract();

       Args                            args = new Args();

       controller.parmReportName(ssrsReportStr(SalesInvoice, Report));

       controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

       controller.parmShowDialog(false);

       salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);

       salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId);

       salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());

       // (1) Try by passing args

       args.record(custInvoiceJour);

       args.parmEnum(PrintCopyOriginal::Original);

       args.parmEnumType(enumNum(PrintCopyOriginal));

       controller.parmReportContract().parmRdpContract(salesInvoiceContract);    

       controller.parmArgs(args);

       // (2) Try explicitly preventing loading from last value

       // controller.parmLoadFromSysLastValue(false);

       // Change print settings as needed

       settings = controller.parmReportContract().parmPrintSettings();

       settings.printMediumType(SRSPrintMediumType::File);

       settings.fileFormat(SRSReportFileFormat::PDF);

       settings.overwriteFile(true);

       settings.fileName(@'C:\Temp\Invoice.pdf');

       controller.startOperation();

    }

  • Community Member Profile Picture
    on at

    Hi,

    Does this print to the printer or a file in temp directory.

    Thanks

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