Skip to main content

Notifications

How to: Get ledger dimension from string in D 365 FOE

I came across a requirement where financial dimensions were coming in XML from integration and Account number was to be determined using business logic. I had to create a general journal from this integration.

So situation is :


  • Find the account number from business login in D 365.
  • Get the financial dimensions from integration.
  • Create a journal line from above info.


Code to do above is as follows:

DimensionDynamicAccount ledgerAccount;
switch(<AccountType>)
{
case (LedgerJournalACType::Cust) :
ledgerJournalTrans.AccountType = LedgerJournalACType::Cust;
ledgerAccount = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(<AccountNum>, LedgerJournalACType::Cust);
ledgerJournalTrans.LedgerDimension = ledgerAccount;
break;
case (LedgerJournalACType::Ledger) :
ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
ledgerAccount = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(MainAccount::findByMainAccountId(<AccountNum>).RecId);
if(<DefaultDimensionIntegrationValues string from integration>)
{
DefaultDimensionIntegrationValues ledgerString = <AccountNum> + enum2Str(DimensionParameters::find().DimensionSegmentDelimiter) + <DefaultDimensionIntegrationValues string from integration>;
LedgerAccountDimensionResolver dimResolver = LedgerAccountDimensionResolver::newResolver(ledgerString);
ledgerAccount = dimResolver.resolve();

}
ledgerJournalTrans.LedgerDimension = ledgerAccount;
break;
case (LedgerJournalACType::Vend) :
ledgerJournalTrans.AccountType = LedgerJournalACType::Vend;
ledgerAccount = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(<AccountNum>, LedgerJournalACType::Vend);

ledgerJournalTrans.LedgerDimension = ledgerAccount;
break;
}


you need to replace <AccountNum> with your Account number variable and <DefaultDimensionIntegrationValues string from integration> with your Financial dimension string.


This was originally posted here.

Comments

*This post is locked for comments