Tuesday, April 16, 2013

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

static void Raj_Demo_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));
}

5 comments:

Unknown said...

journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetAcctPattern));
>> but this code bring nothing to General Journal offset account
I go to method: parmOffsetLedgerDimension
and see the code validate. After checking, it return 0.
if (!this.isFieldSet(fieldNum(LedgerJournalTrans, OffsetLedgerDimension)))

Afsar said...

Its seems to be a bug, I got same issue when I set Offset account of type ledger, the offset field not displayed value, after commented the following line, I can see the offset value
journalTrans.parmOffsetAccountType

TyHj said...

Hi,
Try reverse the order of code then it will show.


offSetAcctPattern = ["401100-Disp","401100", 4, "Department","00000014", "CostCenter", "00000007", "CustomPurposeA","Nile", "CustomPurposeB", "Site2" ];
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetAcctPattern));

journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );

Anonymous said...

You can just call this before setting the offset account:

AxLedgerJournalTrans.clearField(fieldNum(ledgerJournalTrans,offsetLedgerDimension), false);

eddyshaw9272711 said...

Oh my goodness! a tremendous article dude. Thanks Nevertheless I'm experiencing concern with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting an identical rss downside? Anybody who is aware of kindly respond. Thnkx casino games