Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to print ssrs report from X++

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to print ssrs report from X++

    Hi,

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

    Thanks

  • Suggested answer
    Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: How to print ssrs report from X++

    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();

    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    RE: How to print ssrs report from X++

    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
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: How to print ssrs report from X++

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to print ssrs report from X++

    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

  • Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    RE: How to print ssrs report from X++

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

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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans