Tuesday, May 15, 2012

Dynamics AX 2012 - X++ code to create General Journal

static void Demo_CreateGLJournal(Args _args)
{
    AxLedgerJournalTable journalTable;
    AxLedgerJournalTrans journalTrans;
    container            accEntryPattern;
    container            offSetEntryPattern;
    ;

    journalTable = new AxLedgerJournalTable();
    journalTrans = new AxLedgerJournalTrans();

    //Journal Name
    journalTable.parmJournalName("GenJrn");
    journalTable.save();

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(systemDateGet());
    journalTrans.parmAccountType(LedgerJournalACType::Ledger);

    //LedgerDimension  => Ledgeraccount, DAX 2009
    accEntryPattern = ["601501", "601501", 0]; 
    journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accEntryPattern));

    journalTrans.parmAmountCurDebit(2000);

    //OffsetLedgerDimension => OffsetLedgerAccount,  DAX 2009
    offSetEntryPattern = ["401100", "401100", 0];
    journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetEntryPattern));
  
    journalTrans.save();

    info(strFmt("Journal %1 created", journalTable.ledgerJournalTable().JournalNum));
}

How to post with Financial dimensions:

Format : 
["DisplayValue", "MainAccount", NumberOfDimensions, "DimensionName", "DimensionValue"]

E.g:
accEntryPattern = ["601501-Test", "601501", 1, "Department", "OU_1"]

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...