06 December 2013

X++ code for Ledger journal posting with one line / journal posting in AX

Example class for reference: \Classes\TutorialJournalCheckPost\main

Example: Using Ledger Journal
The following is an example of creating a journal with one journal line and then
posting the journal.

static void ExampleLedgerJournal(Args _args)
{
LedgerJournalName LedgerJournalName;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberseq;
LedgerJournalNameId LedgerJournalNameId = 'GenJrn';
BankAccountID BankAccountID = 'EUR OPER';
ledgerAccount offsetAccount = '601500';
amountCur amountCur = 102;
;
ttsbegin;
// Find a ledgerJournalName record
select firstonly LedgerJournalName
where LedgerJournalName.JournalName ==
LedgerJournalNameId;
//Created the ledgerJournalTable
ledgerJournalTable.JournalName =
LedgerJournalName.JournalName;
ledgerJournalTable.initFromLedgerJournalName();
ledgerJournalTable.Name = 'Hotel';
ledgerJournalTable.insert();
numberseq =
NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherS
eries);
ledgerJournalTrans.Voucher = numberseq.voucher();
//Generate the transaction line
ledgerJournalTrans.JournalNum =
ledgerJournalTable.JournalNum;
ledgerJournalTrans.CurrencyCode = 'EUR';
ledgerJournalTrans.ExchRate =
Currency::exchRate(ledgerJournalTrans.CurrencyCode);
ledgerJournalTrans.AccountNum = BankAccountID;
ledgerJournalTrans.AccountType =
LedgerJournalACType::Bank;
ledgerJournalTrans.AmountCurCredit = amountCur;
ledgerJournalTrans.TransDate = today();
ledgerJournalTrans.Txt = 'Room Stay';
ledgerJournalTrans.OffsetAccount = offsetAccount;
ledgerJournalTrans.OffsetAccountType =
LedgerJournalACType::Ledger;
ledgerJournalTrans.insert();
info(strfmt('Journal Id:
%1',ledgerJournalTable.JournalNum));
//Post the Journal
ledgerJournalCheckPost =
ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournal
Table,NoYes::Yes);
ledgerJournalCheckPost.run();
ttscommit;
}

1 comment:

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...