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 we old customer as debit amount and other customer account as offset.
I used following code Snippet to do so but
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 :)). But when I used it as customer I don’t know what reason it let empty the as empty, while during debug value is perfectly 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 at line level to insert directly into table. 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 set current currency code, which possibly by default set 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();
*This post is locked for comments