Create and post free text invoice using X++ code

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.

Creation of Free Text Invoice header

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;
    }

Creation of Free Text Invoice line

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

Posting of Free Text Invoice

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.

Omar Iqbal

Technical Consultant

References:

  1. https://mafsarkhan.blogspot.com/2009/08/create-and-post-free-text-invoice-in-ax.html
  2. https://kishoredynamics11.blogspot.com/2021/07/creating-and-posting-free-text-invoice.html
  3. https://www.schweda.net/blog_ax.php?bid=644&wdl=en
Total
0
Shares
10 comments
  1. Wonderful goods from you, man. I have understand your stuff prior to and you’re simply too excellent. I really like what you have obtained here, really like what you are saying and the way in which by which you say it. You are making it entertaining and you still care for to keep it smart. I cant wait to learn much more from you. That is really a wonderful website.

  2. Heya i am for the first time here. I found this board and I find It really useful & it helped me out a lot.I’m hoping to provide one thing again and help others suchas you aided me.

Comments are closed.

Previous Article

Sales order confirmation using X++ code

Next Article

Set lookup in Microsoft Dynamics CE (CRM) using JavaScript

Related Posts