Friday, November 27, 2015

Dynamics AX 2012 create and post General Journal Using X++

Create and  post General Journal Using X++

static void 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("GL");
journalTable.save();

journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(systemDateGet());
journalTrans.parmCurrencyCode("SAR");
journalTrans.parmAmountCurDebit(1200);
   

acctPattern = ["11030101-01-02","11030101", 2, "Region","01","Branch", "02"];
journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(acctPattern));
journalTrans.parmAccountType(LedgerJournalACType::Ledger);
   

offSetAcctPattern = ["41010101-01-02","41010101", 2, "Region","01","Branch", "02"];
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern));
journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
journalTrans.save();

ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
ledgerJournalCheckPost.run();
info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));
}

Thanks

axLedgerJournalTrans.parmOffsetLedgerDimension is not working in Dynamics AX2012 R3


if you try to create general journal in AX 2012 R3 and the offset Account not set and you are using such of following code


journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger ); 
offSetAcctPattern = ["41010101-01-02","41010101", 2, "Region","01","Branch", "02"]; 
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern)); 
journalTrans.save(); 



Solution is simply:
Reverse the code order to be 


offSetAcctPattern = ["41010101-01-02","41010101", 2, "Region","01","Branch", "02"]; 
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern)); 
journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger ); 
journalTrans.save();