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
omar_iqbal

Recent Posts

Create and Update Rows Using a Plugin in Microsoft Dynamics CE (CRM)

Microsoft Dynamics CRM is a powerful Customer Relationship Management (CRM) tool that helps businesses manage…

2 years ago

Assign record owner to specific Team using Power Automate flow in Microsoft Dynamics CE (CRM)

Today we will be going over the steps how to assign owner to specific Team…

2 years ago

Set lookup in Microsoft Dynamics CE (CRM) using JavaScript

Today we will be going over the steps how to set the value of a…

2 years ago

Sales order confirmation using X++ code

In this article we will be focusing on confirmation of a sales order using X++…

3 years ago

Purchase order confirmation using X++ code

In this article we will be focusing on confirmation of a purchase order using X++…

3 years ago

Create and post inventory ownership change journal using X++ code

In this article we will see how we can create inventory ownership change journal using…

3 years ago