This post is machine-translated. The original post in german language can be found here.

Creating and posting a free text invoice by code

The following job shows how to create and post a free text invoice by code.

static void createAndPostFreeTextInvoice(Args _args)
{
    CustInvoiceTable custInvoiceTable;
    CustInvoiceLine custInvoiceLine;
    DimensionDefault dimensionDefault; 
    LedgerDimensionAccount ledgerDimensionAccount;     
    CustPostInvoice custPostInvoice;
    
    try
    {
        ttsBegin;        
        
        // Create header
        custInvoiceTable.clear();
        custInvoiceTable.initValue();
        custInvoiceTable.OrderAccount = "US-004";
        custInvoiceTable.modifiedField(
            fieldNum(CustInvoiceTable, OrderAccount));
        custInvoiceTable.insert();
        
        // Create line
        custInvoiceLine.clear();
        custInvoiceLine.initValue();
        custInvoiceLine.ParentRecId = custInvoiceTable.RecId;
        custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);
        custInvoiceLine.Description = "Test";
        custInvoiceLine.Quantity = 10;
        custInvoiceLine.modifiedField(
            fieldNum(CustInvoiceLine, Quantity));
        custInvoiceLine.UnitPrice = 200;
        custInvoiceLine.modifiedField(
            fieldNum(CustInvoiceLine, UnitPrice));
        
        ledgerDimensionAccount = 
        DimensionDefaultingService::serviceCreateLedgerDimension(
            DimensionStorage::getDefaultAccountForMainAccountNum(
                "110110"), 
                dimensionDefault); 
        
        custInvoiceLine.LedgerDimension = ledgerDimensionAccount;
        custInvoiceLine.modifiedField(
            fieldNum(CustInvoiceLine, LedgerDimension));
        custInvoiceLine.insert();
        
        // Post
        custPostInvoice = new CustPostInvoice(custInvoiceTable);
        custPostInvoice.run();
        
        ttsCommit;
    }
    catch
    {
        throw error(error::wrongUseOfFunction(funcName()));
    }
}

This is what a free text invoice looks like:

Screenshot Freetext invoice

These post applies to following version:
Dynamics AX 2012

Add comment
 
 

 

 
 
 
Posts of the actual month
November 2019
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
252627282930 
 
© 2006-2019 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.