Interview Questions

Thursday, May 8, 2014

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

static void Gulshan_CreateGLJournalPost(Args _args)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTrans;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    ;

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

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

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(systemDateGet());
    journalTrans.parmCurrencyCode("USD");
    journalTrans.parmAmountCurDebit(200);
   
    journalTrans.parmAccountType(LedgerJournalACType::Ledger);
    acctPattern = ["211345-Disp","211345"2"Department","00000014""CostCenter","00000007"];
   journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(acctPattern));       
   
    journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    offSetAcctPattern = ["401100-Disp","401100"4"Department","00000014""CostCenter","00000007""CustomPurposeA","Nile""CustomPurposeB""Site2" ];    
    journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetAcctPattern));   
   
    journalTrans.save();   
   
    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
    ledgerJournalCheckPost.run();  
   

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

No comments:

Post a Comment