Monday, July 12, 2021

Creating and posting a free text invoice using X++ in D365Fo



        ttsBegin;

        // Create header

        custInvoiceTable.clear();

        custInvoiceTable.initValue();

        custInvoiceTable.OrderAccount = "US-001";

        custInvoiceTable.modifiedField(fieldNum(CustInvoiceTable, OrderAccount));

        custInvoiceTable.insert();

        // Create line

        custInvoiceLine.clear();

        custInvoiceLine.initValue();

        custInvoiceLine.ParentRecId = custInvoiceTable.RecId;

        custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);

        custInvoiceLine.Description = "Free text invoice";

        custInvoiceLine.Quantity = 2;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, Quantity));

        custInvoiceLine.UnitPrice = 100;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, UnitPrice));

        //Get MainAccountId from LedgerDimension

                    LedgerDimensionFacade::getMainAccountFromLedgerDimension(LedgerDimension).MainAccountId;

        //Get Name of MainAccountId from LedgerDimension

        LedgerDimensionFacade::getMainAccountFromLedgerDimension(LedgerDimension).Name;

        ledgerDimensionAccount = DimensionDefaultingService::serviceCreateLedgerDimension(

            DimensionStorage::getDefaultAccountForMainAccountNum("110110"), dimensionDefault);

        custInvoiceLine.LineNum         = CustInvoiceLine::lastLineNum_W(custInvoiceLine.ParentRecId) + 1;

        custInvoiceLine.LedgerDimension = ledgerDimensionAccount;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, LedgerDimension));

        custInvoiceLine.insert();


        // Post

        custPostInvoice = new CustPostInvoice(custInvoiceTable);

        custPostInvoice.run();

        ttsCommit;

    }

    catch

    {

        throw error(error::wrongUseOfFunction(funcName()));

    }


Keep Daxing!!

No comments:

Post a Comment