Category: AX 2012 Codes

AX 2012 | D365: Post Sales Invoice using X++

static void postSalesInvoice(Args _args) { SalesFormLetter salesFormLetter; SalesTable salesTable; SalesId salesId = ‘005063’; System.Exception error; str strError; CustInvoiceJour custInvoiceJour; ; ttsBegin; try { salesTable = SalesTable::find(salesId); if (salesTable && salesTable.SalesStatus == SalesStatus::Delivered) { salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No, NoYes::Yes); if (salesFormLetter.parmJournalRecord().TableId == tableNum(CustInvoiceJour)) { custInvoiceJour = salesFormLetter.parmJournalRecord(); info(strFmt(‘Sales Order #:%1…

Event handler wihle processReport DP X++

class SalesConfirmDPEventHandler { [PostHandlerFor(classStr(SalesConfirmDP), methodStr(SalesConfirmDP, processReport))] public static void SalesConfirmDP_Post_processReport(XppPrePostArgs args) { MCRCustPaymTable custPaymTable; SalesConfirmDP dpInstance = args.getThis() as SalesConfirmDP; SalesTable salesTableLocal; MCRCustPaymTableTmp custPaymTableTmp; custPaymTableTmp = dpInstance.getMCRCustPaymTable(); salesTableLocal = SalesTable::find(dpInstance.parmCustConfirmJour().SalesId); while select custPaymTable where custPaymTable.RefTableId == salesTableLocal.TableId && custPaymTable.RefRecId == salesTableLocal.RecId { custPaymTableTmp.clear(); custPaymTableTmp.initValue(); custPaymTableTmp.TenderTypeId = custPaymTable.TenderTypeId; custPaymTableTmp.TenderTypeName = custPaymTable.displayName(); custPaymTableTmp.Amount = custPaymTable.Amount; custPaymTableTmp.insert(); }…

Sending Email using X++ Code (AX2012/D365)

class SRSendEmail_D365 {     public static void main(Args _args)     {         SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();         Email   toEmail;         Email   fromEmail;         try         {             FromEmail = “sreddy@xyzcompany.com”;             toEmail   = “tester@xyzcompany.com”;             messageBuilder.setBody(“Hello from D365”, false);             messageBuilder.setSubject(“Email Test from D365”);             messageBuilder.addTo(toEmail);             // Note: not calling setFrom() defaults to the current user for SMTP client, whereas             // when sent to Outlook any setFrom() value will be ignored since profiles on the client are used             messageBuilder.setFrom(fromEmail);             //…

This is sample Code to get opening balance for Ledger Main account in Ax 2012.

LedgerBalanceMainAccountAmounts ledgerBalance; AmountMst opSum; ; ledgerBalance = LedgerBalanceMainAccountAmounts::construct(); ledgerBalance.parmIncludeRegularPeriod(true); ledgerBalance.parmIncludeOpeningPeriod(true); ledgerBalance.parmIncludeClosingPeriod(false); ledgerBalance.parmAccountingDateRange(mkDate(01,01,2000), mkDate(31,12,2017)); ledgerBalance.calculateBalance(MainAccount::findByMainAccountId(‘1123333’)); opSum = ledgerBalance.getAccountingCurrencyBalance(); info(num2str(opSum,10,2,1,1));

AX 2012: Clear the cache

In this post I would like to share the job. The purpose of this job is to clear Local Cache. Every time when I see doubtful behavior, I run this job to make sure that AX is not misbehave. static void RefreshLocalCache(Args _args) { xSession::removeAOC(); SysTreeNode::refreshAll(); SysFlushDictionary::main(null); SysFlushAOD::main(null); SysFlushData::main(null); SysBPCheckAIFDataObject::flushCache(true); SysFlushReportServer::main(null); SysFlushSystemSequence::main(null); xSession::updateAOC(); info(“ok”);

Upload and read CSV files in Dynamics 365 for operations

To quickly reuse the code here it goes class RGReadSample { /// /// Runs the class with the specified arguments. /// /// The specified arguments. public static void main(Args _args) { AsciiStreamIo                                   file; Array                                           fileLines; FileUploadTemporaryStorageResult                fileUpload; fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult; file = AsciiStreamIo::constructForRead(fileUpload.openResult()); if (file) { if (file.status()) { throw error(“@SYS52680”); } file.inFieldDelimiter(‘,’); file.inRecordDelimiter(‘\r\n’);…