Playing with SSRS report in dynamics ax 2012

here is the simple code that i have created to print the SSRS report in dynamics ax 2012 from different scenarios.

How to print the SSRS report in dynamics ax 2012 from code.

    SrsReportRun srsReportRun;

    // initiate the report.
    srsReportRun = new SrsReportRun ("InventTruckTransactionReport.PrecisionDesign1");
    srsReportRun.init();
    srsReportRun.reportCaption("InventTruckTransactionReport.PrecisionDesign1");
    // set parameters name, value.
    srsReportRun.reportParameter("TruckTransDS_JournalId").value("000161_070");
    // suppress the dialog
    srsReportRun.showDialog(false);

    if( srsReportRun )
    {
        // run the report 
        srsReportRun.executeReport();
    }

How to save the SSRS report to PDF/HTML through code in dynamics ax 2012.

    SrsReportRun srsReportRun;

    srsReportRun = new SrsReportRun("InventTruckTransactionReport.PrecisionDesign1");

    srsReportRun.init();
    srsReportRun.reportCaption("InventTruckTransactionReport.PrecisionDesign1");
    srsReportRun.reportParameter("TruckTransDS_JournalId").value("000161_070");
    srsReportRun.showDialog(false);

    // Print to a file named ReportExample in HTML/PDF format.
    srsReportRun.printDestinationSettings().printMediumType(SRSPrintMediumType::File);
    srsReportRun.printDestinationSettings().fileFormat(SRSReportFileFormat::PDF);
    srsReportRun.printDestinationSettings().overwriteFile(true);
    srsReportRun.printDestinationSettings().fileName(@"C:\InventTruckTransactionReport.pdf");

    if( srsReportRun )
    {
        srsReportRun.executeReport();
    }

Some important sales order / purchase order operations AX 2009

HAPPY NEW YEAR GUYS πŸ™‚Β 

Recently i got chace to work on sales order screen simplification where i need to simplify the operations of sales orders, for that i would need to customizae some main operations. i am listing the logics of some of the main operations.

How to create SALE ORDER from code in dynamics ax.

static void createSalesTable(CustAccount _custAccount) {

SalesTable salesTable;
NumberSeq NumberSeq;
;
NumberSeq = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence);
salesTable.SalesId = NumberSeq.num();
salesTable.initValue();
salesTable.CustAccount = _custAccount;
salesTable.initFromCustTable();
salesTable.insert();
}

static void createSalesLine(SalesId _salesId, ItemId _itemId) {
SalesLine salesLine;
;
salesLine.clear();
salesLine.SalesId = _salesId;
salesLine.ItemId = _itemId;
salesLine.createLine(NoYes::Yes, // Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::Yes); // searchPrice
}

How to POST Sales order from code?

please follow the below link https://msdax.wordpress.com/2010/06/29/posting-invoice-from-sales-order-purchase-order/

How to create return Order from code:

Β static void SR_CreateReturnOrderAfterInvoice(Args _args)
 {
 CustInvoiceJour _invoiceRec;
 str _returnReason;
 CustInvoiceTrans custInvoiceTrans;
 SalesLine salesLine;
 SalesTable newRetOrder;
 CustInvoiceJour custInvoiceJour;

SalesTable createReturnOrderHeader(CustInvoiceJour invoiceRec)
 {

SalesTable old, newRec;
 boolean bChecksOk = true;
 ;

old = SalesTable::find(invoiceRec.SalesId);
 newRec.initReturnFromSalesTable(old);
 newRec.CustAccount = old.CustAccount;

newRec.initFromCustTable();

newRec.CustInvoiceId = invoiceRec.InvoiceId;
 newRec.ReturnDeadline = today();
 newRec.ReturnReasonCodeId = ’21β€²; // Defective
 newRec.SalesType = SalesType::ReturnItem;
 newRec.SalesTaker = SysCompanyUserInfo::current().EmplId;

if ( newRec.ReturnReasonCodeId == ” && CustParameters::find().ReturnOrdersReasonReq ||
 newRec.ReturnReasonCodeId != ” && !ReturnReasonCode::exist(newRec.ReturnReasonCodeId) )
 {
 checkFailed(strfmt(β€œ@SYS26332β€³, fieldid2pname(tablenum(SalesTable), fieldnum(SalesTable, ReturnReasonCodeId))));
 bChecksOk = false;
 }

if ( bChecksOk && newRec.validateWrite())
 {
 newRec.insert();
 }
 else
 {
 throw error(β€œ@SYS18722β€³);
 }

return newRec;
 }

ttsbegin;

// first we need to create the sales order header for the return order
 select custInvoiceJour where custInvoiceJour.RefNum == RefNum::SalesOrder && custInvoiceJour.InvoiceId == ’101231β€²;

newRetOrder = createReturnOrderHeader(custInvoiceJour);

while select * from custInvoiceTrans where custInvoiceTrans.SalesId == custInvoiceJour.SalesId
 && custInvoiceTrans.InvoiceId == custInvoiceJour.InvoiceId
 && custInvoiceTrans.InvoiceDate == custInvoiceJour.InvoiceDate
 && custInvoiceTrans.numberSequenceGroup == custInvoiceJour.numberSequenceGroup
 {
 // now we need to populate all the necessary fields for the new salesline
 // using the existing invoice and the new sales order
 salesLine.initFromCustInvoiceTrans(custInvoiceTrans);
 salesLine.initFromSalesTable(newRetOrder);

// udpate the quantity
 salesLine.ExpectedRetQty = -custInvoiceTrans.Qty;

if (salesLine.ExpectedRetQty > 0)
 {
 error(β€œ@SYS53512β€³);
 ttsabort;
 }

// set the quantity and amount fields
 salesLine.LineAmount = salesLine.returnLineAmount();
 salesLine.SalesQty = 0;
 salesLine.InventTransIdReturn = custInvoiceTrans.InventTransId;

//create the line
 salesLine.createLine(true, false, false, false, false, false, false, false, salesLine.InventTransId);

// clear the buffer
 salesLine.clear();
 }

ttscommit;

info(strfmt(β€˜Newly created return order is %1β€², newRetOrder.SalesId));

}

How to print Performa Sales Invoice?

static void Test_SalesFormLetter(Args _args)
{
    SalesFormLetter letter=SalesFormLetter::construct(DocumentStatus::Invoice);
    SalesTable sale = SalesTable::find('ORDR00000229');
;
    ttsBegin;
    letter.update(sale, systemDateGet(), SalesUpdate::PickingList, AccountOrder::None, true, true);
    ttsCommit;
}

How to print sales Invoice ?

public void printInvoiceReport(PurchId _purchId)
{
    ReportRun report;
    RecordSortedList List = new RecordSortedList(tableNum(VendInvoiceJour));

    VendInvoiceJour VendInvoiceJour = VendInvoiceJour::findFromPurchId(_purchId);
    PurchFormLetter PurchFormLetter;
    ;

    if (VendInvoiceJour.RecId)
    {

        report = new ReportRun(new Args(ReportStr(PurchInvoice)));

        List.ins(VendInvoiceJour);
        report.args().object(List);
        report.query().interactive(false);
        report.report().interactive(false);
        report.args().parmEnum(0);
        report.args().parmEnumType(920);

        report.args().name("KeepSettings");
        report.args().caller(PurchFormLetter);
        report.setTarget(PrintMedium::Screen);
        report.printJobSettings().setTarget(PrintMedium::Screen);
        report.printJobSettings().preferredTarget(PrintMedium::Screen);

        PurchFormLetter     =   PurchFormLetter::construct(DocumentStatus::Invoice);
        PurchFormLetter.updatePrinterSettingsFormLetter(report.printJobSettings().packPrintJobSettings(), PrintSetupOriginalCopy::Original);
        PurchFormLetter.updatePrinterSettingsFormLetter(report.printJobSettings().packPrintJobSettings(), PrintSetupOriginalCopy::Copy);

        // print invoice
        VendInvoiceJour.printJournal(PurchFormLetter);
    }
}
Thanks to few links that i have found
http://dynamicsaxgyan.wordpress.com/2010/12/17/create-return-order-using-x/
http://www.axaptapedia.com/SalesFormLetter_class
http://community.dynamics.com/product/ax/axtechnical/b/dynamicsaxposed/archive/2011/10/11/how-to-create-sales-order-through-code.aspx