Skip to main content

Print Report in Microsoft Dynamics AX 2009 through X++

I am trying to print sales confirmation report on a button click which I have added on Sales Order Detail form in Microsoft Dynamics AX 2009. On click event of that button, I have written following code:
void clicked()
{
    Args                args;
    ReportRun           reportRun;
    SalesFormLetter     salesFormLetter;
    PrintJobSettings    printJobSettings;
    CustConfirmJour     custConfirmJour;
    RecordSortedList    list                = new RecordSortedList(55);
    SalesTable          salesTableUpdate;
    ;

    SELECT firstonly custConfirmJour order by ConfirmID desc where custConfirmJour.SalesId == salesTable.SalesId ;

    list.ins(custConfirmJour);

    args = new Args(ReportStr(SalesConfirm));


    printJobSettings = new PrintJobSettings();
    printJobSettings.SetTarget(PrintMedium::Printer);
    printJobSettings.suppressScalingMessage(true);

    salesFormLetter  = new SalesFormLetter_Confirm(true);
    salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());

    args.designName("Standard");
    args.caller(salesFormletter);
    args.parmEnum(PrintCopyOriginal::Original);
    args.parmEnumType(enumnum(PrintCopyOriginal));
    args.object(list);

    reportRun = new ReportRun(args);
    reportRun.setTarget(PrintMedium::Printer);
    reportRun.init();
    reportRun.run();
}

try this:
public void run()
{
Args args; ReportRun report;
str printer;
PrintJobSettings pjs;
 ;
args = new Args(reportstr("PwC_ExciseInvoice_Sales"));
counter = 1;
pjs = new printJobSettings();
while(counter <= maxReports)
{
    args.parm(int2str(counter));
    args.record(custInvoiceJour);
    report = new ReportRun(args);
    pjs.setTarget(PrintMedium::Printer);
    report.setTarget(PrintMedium::Printer);
    report.init();
    report.run();

    counter++;
}
}

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }