Category: X++ Methods

AX 2012 | D365: Post Packing Slip using X++

static void postPackingSlip(Args _args) { SalesFormLetter salesFormLetter; SalesTable salesTable; SalesId salesId = ‘SO00001’; System.Exception error; str strError; CustPackingSlipJour custPackingSlipJour; ; ttsBegin; try { salesTable = SalesTable::find(salesId); if (salesTable && salesTable.SalesStatus == SalesStatus::Backorder) { salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip); salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::PackingSlip, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No); if (salesFormLetter.parmJournalRecord().TableId == tableNum(custPackingSlipJour)) { custPackingSlipJour = salesFormLetter.parmJournalRecord(); info(strFmt(‘New Packing Slip #:%1…

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…

[D365] How to add a custom report type to print management setup X++

The simple way to add new report or new design of existing report in Print management Step-1 Create new class SLD_DemoSample Step-2 Find class PrintMgmtDocType in Application Explore and open in designer Step-3 find the delegate in PrintMgmtDocType class  Delegate name is  getDefaultReportFormatDelegate Step-4 Subscribe the event of above highlighted event in the newly created class Step-5 Now add the…

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

Pass Args as record from onclick event handler to menu item D365fo [X++]

/// <summary> /// /// </summary> /// <param name=”sender”></param> /// <param name=”e”></param> [FormControlEventHandler(formControlStr(DocuView, Print), FormControlEventType::Clicked)] public static void Print_OnClicked(FormControl sender, FormControlEventArgs e) { Args args = new Args() ; DocuRef _DocuRef ; FormRun _formRun = sender.formrun() as FormRun ; FormDataSource _ds ; _ds =sender.formRun().dataSource(1); _DocuRef = _ds.cursor(); args.record(_DocuRef); // calling menu item new MenuFunction(identifierstr(DocuViewPrint), MenuItemType::Action).run(args); }

Current user and its employee Name and department X++

static void curUserInfo(Args _arg) { str sUserId; Name name; str departmentName ; ; sUserId = curUserId(); info( “Current user ID is ” + sUserId ); name= HcmWorker::find(DirPersonuser::findUserWorkerReference(sUserId)).name(); departmentName= HcmWorker::find(DirPersonuser::findUserWorkerReference(sUserId)).primaryDepartmentName(); info (“Name is ” + name); }

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);             //…

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