web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

X++ code to create and post general journal posting in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

HI,

In this post we will view the code to create and post a general journal. For demo purpose, Ledger Dimension and Offset ledger dimension values are supplied with record Id of the dimension combination table. In my next post, I will provide the code without hard coding these values.

Step 1: Created a runnable class by name CG_CreatePostGeneralJournal and written below to create & post a journal.

class CG_CreatePostGeneralJournal
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost journalCheckPost;
LedgerJournalName ledgerJournalName;
NumberSeq numberseq;
Voucher voucher;

select firstonly ledgerJournalName
where ledgerJournalName.JournalName == "GenJrn";
// Header
ledgerJournalTable = null;
ledgerJournalTable.company("USMF");
ledgerJournalTable.JournalName = ledgerJournalName.JournalName;
ledgerJournalTable.initFromLedgerJournalName();
ledgerJournalTable.NumberSequenceTable = ledgerJournalName.NumberSequenceTable;
ledgerJournalTable.insert();

if (ledgerJournalTable.RecId)
{
// Line
ledgerJournalTrans = null;
ledgerJournalTrans.Company = "USMF";
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.TransDate = today();
ledgerJournalTrans.LineNum = LedgerJournalTrans::lastLineNum(ledgerJournalTrans.JournalNum);

voucher = new JournalVoucherNum(JournalTableData::newTable(ledgerJournalTable)).getNew(false);

ledgerJournalTrans.Voucher = voucher;
ledgerJournalTrans.CurrencyCode = 'USD';
ledgerJournalTrans.AmountCurDebit = 10;
ledgerJournalTrans.ExchRate = 1.00;

ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
ledgerJournalTrans.LedgerDimension = 6871XXXXXXX;

ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Bank;
ledgerJournalTrans.OffsetLedgerDimension = 2256XXXXXXX;

ledgerJournalTrans.insert();

if (ledgerJournalTrans.RecId)
{
// Posting
journalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
journalCheckPost.runOperation();

ledgerJournalTable.reread();
if (ledgerJournalTable.Posted == NoYes::Yes)
{
info(strFmt("Journal %1 has been created and posted.", ledgerJournalTable.JournalNum));
}
}
}
}

}

Step 2: Executed the runnable class.

Execution.jpg

Step 3: After processing the runnable class, journal has been created and posted.

Posted.jpg

Regards,

Chaitanya Golla

Comments

*This post is locked for comments