≡ Menu




Customer as offset account Dynamics Ax 2012 R3

During one of my customization, I have to transfer customer balance from one customer to another, for this purpose

ledger entry for old customer as debit amount and other customer account set in offset account.

 

I used following code Snippet to achieve this functionality

LedgerJournalCheckPost  jourCheckPost;

LedgerJournalTable      jourTable;

 

AxLedgerJournalTable    header  = new AxLedgerJournalTable();

AxLedgerJournalTrans    trans   = new AxLedgerJournalTrans();

 

container               offsetDim;

LedgerJournalNameId     ledgerJournalNameId = “payment”;

LedgerJournalACType         accType, offsetAccType;

BankAccountTable            bankAccountTable;

accType         = LedgerJournalACType::Cust;

offsetAccType   = LedgerJournalACType::Cust;

 

header.parmJournalName(ledgerJournalNameId);

header.parmJournalType(LedgerJournalType::CustPayment);

header.save();

 

 

 

select firstOnly RecId from ToCustomer

where ToCustomer.DisplayValue == _ToAccount;

 

;

select firstOnly RecId from FromCustomer

where FromCustomer.DisplayValue == _OldAccount;

 

 

trans.parmLedgerDimension(ToCustomer.RecId);

trans.parmAmountCurCredit(PaymentAmount);

trans.parmOffsetAccountType(offsetAccType);

trans.parmOffsetLedgerDimension (FromCustomer.RecId);

trans.save();

 

 

 

 

The above mentioned code works 100 percent fine when I give offset account as ledger or bank ( did not try for vendor :)). When I used customer as offset I don’t know what reason it let offset account as empty. I debug  the code and watch windows show that valide value is parked at  trans.parmOffsetLedgerDimension

 

I don’t know it bug in Dynamics Ax 2012 R3, or some issue in my development environment, After 1 hours try and try, I decided to shift the code to enter data directly into table at line level. That works perfectly fine and entry is successfully parked and show on screen.

Only one extra line of code I need to add that is to set current currency code for ledger entry, which possibly set by default in  ABC classes

New code snippet is something similar at line level

 

LedgerJournalTrans  trans;

 

 

DimensionAttributeValueCombination  FromCustomer,ToCustomer;

 

LedgerJournalACType         accType, offsetAccType;

 

accType         = LedgerJournalACType::Cust;

offsetAccType   = LedgerJournalACType::Cust;

 

trans.AccountType = accType;

trans.OffsetAccountType =offsetAccType;

 

// ledger Header

trans.JournalNum = _JournalNum;

 

trans.CurrencyCode = Ledger::accountingCurrency(CompanyInfo::current());

 

trans.AmountCurDebit = PaymentAmount;

 

 

select firstOnly RecId from ToCustomer

where ToCustomer.DisplayValue == _ToAccount;

 

;

select firstOnly RecId from FromCustomer

where FromCustomer.DisplayValue == _OldAccount;

 

 

trans.LedgerDimension =FromCustomer.RecId;

trans.OffsetLedgerDimension = ToCustomer.RecId;

trans.insert();

 

{ 0 comments… add one }

Leave a Comment