AX2012: Re-read main account default financial dimensions in the General journal line based on the Main account selected

In this blog post, I would like to provide a recipe for updating default financial dimensions based on the Main account selected in the General journal line

I have faced the following difficulty upon main account balance migration through DMF:

When I tried to migrate the main account balances, default financial dimensions were taken from other legal entity where the same account existed and not from the legal entity to where I imported the data.

The easiest way to fix this issue was to create a job that will go through the general journal lines, identifies the main account and based on the main account selected, will update financial dimensions.

Imagine the case, that we have the following general journal line:

general journal line

We have main account 210000 in our journal line. We have incorrect default financial dimensions populated. Let’s say that in our case, the cost center was wrong. Instead of 0000, it should be 1000.

coa

This job, will read the default financial dimensions of the main account and update the journal lines:

static void GLJournalUpdate(Args _args)

{

    Dialog                  dialog = new Dialog(“GL journal update”);

    DialogField             dlgJournalId;

    LedgerJournalId         journalId;

    LedgerJournalTable      ledgerJournalTable;

    LedgerJournalTrans      ledgerJournalTrans;

    Counter                 updatedLines;

    MainAccountNum          curMainAccountNum;

    RecId                   accountStructureRecId;

    MainAccount             curMainAccount;

    DimensionAttributeValueCombination dimAttrValueCombination;

    MainAccountLegalEntity  mainAccountLegalEntity;

    DimensionDefault        curAccountDefaultDim;

    RecId                   newLedgerDimension;

    ;

    dialog = new Dialog();

    dlgJournalId = dialog.addFieldValue(extendedTypeStr(LedgerJournalId), journalId);

    if (dialog.run())

    {

        journalId = dlgJournalId.value();

 

        if (journalId)

        {

            startLengthyOperation();

            ttsBegin;

            while select forupdate ledgerJournalTrans

                where ledgerJournalTrans.JournalNum == journalId

           {

                curMainAccount = DimensionStorage::getMainAccountFromLedgerDimension(ledgerJournalTrans.LedgerDimension);

                accountStructureRecId = DimensionHierarchy::getAccountStructure(curMainAccount.RecId);

                curAccountDefaultDim =

MainAccountLegalEntity::findByMainAccountLegalEntity(DimensionStorage::getMainAccountIdFromLedgerDimension(ledgerjournaltrans.LedgerDimension),CompanyInfo::current()).DefaultDimension;

                newLedgerDimension = DimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(curMainAccount.RecId, accountStructureRecId, curAccountDefaultDim);

                ledgerJournalTrans.LedgerDimension = newLedgerDimension;

                ledgerJournalTrans.doUpdate();

                updatedLines++;

            }

            ttsCommit;

            endLengthyOperation();

            info (strFmt(“%1 line(s) have been updated”, updatedLines));

        }

        else

        {

            warning (“Journal number must be specified”);

        }

    }

}

 

That’s it!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s