In this article we will see how we can create and post free text invoice using X++ code in Microsoft Dynamics Finance & Operations.
We will create a new class named as FreeTextInvoiceHelper and in this class we will add some methods and using those method we will create and post free text invoice.
Create a new method named as createCustInvoiceHeader in this class to create the CustInvoiceTable record.
public CustInvoiceTable createCustInvoiceHeader(TransDate _invoiceDate , DueDate _dueDate, CustAccount _custAccount = '', CustGroupId _custGroup = '') { CustInvoiceTable custInvoiceTable; CustTable custTable; custTable = CustTable::find(_custAccount); custInvoiceTable.initFromCustTable(custTable); custInvoiceTable.CustGroup = _custGroup; custInvoiceTable.OrderAccount = _custAccount; custInvoiceTable.InvoiceAccount = _custAccount; custInvoiceTable.modifiedField(fieldNum(CustInvoiceTable, OrderAccount)); custInvoiceTable.InvoiceDate = _invoiceDate; custInvoiceTable.DueDate = _dueDate; if(custInvoiceTable.validateWrite()) { custInvoiceTable.insert(); } return custInvoiceTable; }
Create a new method named as createCustInvoiceLine in this class to create the CustInvoiceLine record.
public void createCustInvoiceLine(CustInvoiceTable _custInvoiceTable, TransactionTextLarge _description = '', TaxItemGroup _taxItemGroup = '', TaxGroup _taxGroup = '', InvoiceQuantity _qty = 1, InvoiceUnitPrice _unitPrice = 1, LedgerDimensionValueSet _defaultDimension = 0, LedgerDimensionDefaultAccount _ledgerDimension = 0) { CustInvoiceLine custInvoiceLine; LineNum lineNum; custInvoiceLine.initValue(); custInvoiceLine.initFromCustInvoiceTable(_custInvoiceTable); custInvoiceLine.Description = _description; custInvoiceLine.TaxItemGroup = _taxItemGroup; custInvoiceLine.TaxGroup = _taxGroup; custInvoiceLine.ParentRecId = _custInvoiceTable.RecId; custInvoiceLine.Quantity = _qty; custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, Quantity)); custInvoiceLine.UnitPrice = _unitPrice; custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, UnitPrice)); custInvoiceLine.AmountCur = custInvoiceLine.Quantity * custInvoiceLine.UnitPrice; custInvoiceLine.DefaultDimension = _defaultDimension; custInvoiceLine.LedgerDimension = _ledgerDimension; if(!lineNum) { lineNum = CustInvoiceLine::lastLineNum_W(custInvoiceLine.ParentRecId); } lineNum += 1; custInvoiceLine.LineNum = lineNum; if(custInvoiceLine.validateWrite()) { custInvoiceLine.insert(); } }
For posting a free text invoice we will create another method named as postCustInvoice, this takes CustInvoiceTable record as parameter.
public void postCustInvoice(CustInvoiceTable _custInvoiceTable) { CustPostInvoice custPostInvoice; custPostInvoice = new CustPostInvoice(_custInvoiceTable); ttsbegin; custPostInvoice.run(); ttscommit; }
Thank you for reading this article hope you find it useful.
Technical Consultant
References:
Microsoft Dynamics CRM is a powerful Customer Relationship Management (CRM) tool that helps businesses manage…
Today we will be going over the steps how to assign owner to specific Team…
Today we will be going over the steps how to set the value of a…
In this article we will be focusing on confirmation of a sales order using X++…
In this article we will be focusing on confirmation of a purchase order using X++…
In this article we will see how we can create inventory ownership change journal using…