Wednesday 5 February 2014

Creating and posting a ledger voucher in ax 2012

1. Double-check that the getLedgerDimension() method exists in the
DimensionAttributeValueCombination table. If not, create it as described in the first
recipe in this chapter.
2. In the AOT, create a new job named LedgerVoucherPost with the following code:
static void LedgerVoucherPost(Args _args)
{
LedgerVoucher voucher;
LedgerVoucherObject voucherObj;
LedgerVoucherTransObject voucherTrObj1;
LedgerVoucherTransObject voucherTrObj2;
DimensionDynamicAccount ledgerDim;
DimensionDynamicAccount offsetLedgerDim;
CurrencyExchangeHelper currencyExchHelper;
CompanyInfo companyInfo;
ledgerDim =
DimensionAttributeValueCombination::getLedgerDimension(
'110180',
['Department', 'CostCenter', 'ExpensePurpose'],
['OU_2311', 'OU_3568', 'Training']);
offsetLedgerDim =
DimensionAttributeValueCombination::getLedgerDimension(
'170150',
['Department', 'CostCenter', 'ExpensePurpose'],
['OU_2311', 'OU_3568', 'Training']);
voucher = LedgerVoucher::newLedgerPost(DetailSummary::Detail,SysModule::Ledger,'');
voucherObj = LedgerVoucherObject::newVoucher('TEST00001');
companyInfo = CompanyInfo::findDataArea(curext());
currencyExchHelper = CurrencyExchangeHelper::newExchangeDate(
Ledger::primaryLedger(companyInfo.RecId),
voucherObj.parmAccountingDate());
voucher.addVoucher(voucherObj);
voucherTrObj1 =
LedgerVoucherTransObject::newTransactionAmountDefault(
voucherObj,
LedgerPostingType::LedgerJournal,
ledgerDim,
'USD',
1000,
currencyExchHelper);
voucherTrObj2 =
LedgerVoucherTransObject::newTransactionAmountDefault(
voucherObj,
LedgerPostingType::LedgerJournal,
offsetLedgerDim,
'USD',
-1000,
currencyExchHelper);
voucher.addTrans(voucherTrObj1);
voucher.addTrans(voucherTrObj2);
voucher.end();
info(strFmt(
"Voucher '%1' has been posted", voucher.lastVoucher()));
}

3. Run the class to create a new ledger voucher.
4. To check what has been posted, open General Ledger | Inquiries | Voucher
transactions and type in the voucher number used in the code:

5. Click on OK to display the posted voucher:

1 comment:

  1. Can you please provide the link for your first point getledgerdimension() method.

    ReplyDelete