Create and Post general journal through X++

Hi,

I want to create and post general journal through X++ in AX 2012 R3. Please help.

There are many sources over web, here is one.
blogs.msdn.microsoft.com/…/
For posting you can use LedgerJournalCheckPost class.

For posting,

ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
ledgerJournalCheckPost.run();

Hi Kranthi,
I wrote below code but it’s giving error - "The transactions on voucher ---- do not balance as per --/–/---- "

AxLedgerJournalTable _JournalTable;
AxLedgerJournalTrans _JournalTrans;
container _acctPattern;
container _offSetAcctPattern;
LedgerJournalTable _LedgerJournalTable;
LedgerJournalCheckPost _LedgerJournalCheckPost;
GeneralJournalAccountEntry _GeneralJournalAccountEntry;
GeneralJournalEntry _GeneralJournalEntry;
;

super();

if (Box::yesNo("@SYS4003612",DialogButton::Yes) == DialogButton::Yes)
{
_JournalTable = new AxLedgerJournalTable();
_JournalTrans = new AxLedgerJournalTrans();

select _GeneralJournalAccountEntry where _GeneralJournalAccountEntry.PaymentReference == Voided_PaymentReceipts.salesOrderId;
select _GeneralJournalEntry where _GeneralJournalEntry.RecId == _GeneralJournalAccountEntry.GeneralJournalEntry;

_JournalTable.parmJournalName(“Normal_CSC”);
_JournalTable.save();

_JournalTrans.parmJournalNum(_JournalTable.ledgerJournalTable().JournalNum);
_JournalTrans.parmTransDate(_GeneralJournalEntry.AccountingDate);
_JournalTrans.parmCurrencyCode(_GeneralJournalAccountEntry.TransactionCurrencyCode);
if (_GeneralJournalAccountEntry.AccountingCurrencyAmount > 0)
{
_JournalTrans.parmAmountCurDebit(_GeneralJournalAccountEntry.AccountingCurrencyAmount);
}
else
{
_JournalTrans.parmAmountCurCredit(- _GeneralJournalAccountEntry.AccountingCurrencyAmount);
}

_JournalTrans.parmAccountType(LedgerJournalACType::Ledger);
_JournalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
_JournalTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimFromLedgerDim(_GeneralJournalAccountEntry.LedgerDimension));

_JournalTrans.save();

_LedgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(_JournalTable.ledgerJournalTable(),NoYes::Yes);
_LedgerJournalCheckPost.run();

info(strFmt("Journal No %1 ",_JournalTable.ledgerJournalTable().JournalNum));
}

Check if you are filling the offsetLedgerDimension?

_JournalTrans.parmOffsetLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimFromLedgerDim(_GeneralJournalAccountEntry.LedgerDimension));

is it correct way? I tried but still giving error. I am not getting what to specify?

You are filling the same value in both ledgerDimension and offsetLedgerDimension.

What you are trying to achieve with this code?

I want to post journal by using X++. Actually I want to pass journal against specific record for reversal effects through X++.

So you want to created a reversal for the journal transactions/Voucher? if so you already have a similar functionality.
In the journal lines , click functions button and load ledger transactions.

I know this. Same thing I want to process through X++.

That is also written in X++. You can use the same logic.

Ok!

Class name is “LedgerJournalGetTrans”, is it? Please confirm so that I will come to know that I am on correct track.

Hope this will help …

www.blogger.com/blogger.g

can you send me code details , it’s asking me login and right now I don’t have gmail login.

static void VendPaymJournalCreate(Args _args)
{
LedgerJournalTable jourTable;
LedgerJournalTrans jourTrans;
LedgerJournalTableData jourTableData;
LedgerJournalTransData jourTransData;
LedgerJournalStatic jourStatic;
DimensionDynamicAccount ledgerDim;
DimensionDynamicAccount offsetLedgerDim;
ledgerjournalcheckpost post ;
LedgerJournalTable tablepost;
ttsBegin;
ledgerDim = DimensionStorage::getDynamicAccount(‘V000002’,LedgerJournalACType::Vend);
offsetLedgerDim = DimensionStorage::getDynamicAccount(‘ABDI316053’,LedgerJournalACType::Bank);
jourTableData = JournalTableData::newTable(jourTable);
jourTable.JournalNum = jourTableData.nextJournalId();
jourTable.JournalType = LedgerJournalType::Payment;
jourTable.JournalName = ‘PV16’;
jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.JournalName));
jourStatic = jourTableData.journalStatic();
jourTransData = jourStatic.newJournalTransData(jourTrans,jourTableData);
jourTransData.initFromJournalTable();
jourTrans.CurrencyCode = ‘AED’;
jourTrans.initValue();
jourTrans.TransDate = systemDateGet();
jourTrans.AccountType = LedgerJournalACType::Vend;
jourTrans.LedgerDimension = ledgerDim;
jourTrans.Txt = ‘Vendor payment journal demo’;
jourTrans.OffsetAccountType = LedgerJournalACType::Bank;
jourTrans.OffsetLedgerDimension = offsetLedgerDim;
jourTrans.AmountCurDebit = 1000;
jourTransData.create();
jourTable.insert();
tablepost = jourTable;
ttsCommit;
info(strFmt(“Journal ‘%1’ has been created”, jourTable.JournalNum));
//LedgerJournalTable table;
//ledgerjournalcheckpost post ;
//;
//table = //LedgerJournalTable::find(“JB0000191”);
post = LedgerJournalCheckPost::newLedgerJournalTable(tablepost,true,true);

// post = new LedgerJournalcheckPost::newLedgerJournalTable(table,NoYes::Yes,NoYes::Yes);
post.run();
info(“Done”);

}

Modify it accordingly

Before that code create new class for "LedgerJournalTransData " with below code

class LedgerJournalTransData extends JournalTransData
{
}

public void create(boolean _doInsert = false,boolean _initVoucherList = true)
{
lastLineNum++;
journalTrans.LineNum = lastLineNum;
if (journalTableData.journalVoucherNum())
{
this.initVoucher(lastVoucher,false,_initVoucherList);
}
this.addTotal(false, false);
if (_doInsert)
{
journalTrans.doInsert();
}
else
{
journalTrans.insert();
}
if (journalTableData.journalVoucherNum())
{
lastVoucher = journalTrans.Voucher;
}
}

Here is the Simple job. Create the new class first "LedgerJournalTransData " and just copy paste the code in jobs and change accordingly …

static void VendPaymJournalCreate(Args _args)
{
LedgerJournalTable jourTable;
LedgerJournalTrans jourTrans;
LedgerJournalTableData jourTableData;
LedgerJournalTransData jourTransData;
LedgerJournalStatic jourStatic;
DimensionDynamicAccount ledgerDim;
DimensionDynamicAccount offsetLedgerDim;
ttsBegin;
ledgerDim = DimensionStorage::getDynamicAccount(‘V000002’,LedgerJournalACType::Vend);
offsetLedgerDim = DimensionStorage::getDynamicAccount(‘ABDI316053’,LedgerJournalACType::Bank);
jourTableData = JournalTableData::newTable(jourTable);
jourTable.JournalNum = jourTableData.nextJournalId();
jourTable.JournalType = LedgerJournalType::Payment;
jourTable.JournalName = ‘PV16’;
jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.JournalName));
jourStatic = jourTableData.journalStatic();
jourTransData = jourStatic.newJournalTransData(jourTrans,jourTableData);
jourTransData.initFromJournalTable();
jourTrans.CurrencyCode = ‘AED’;
jourTrans.initValue();
jourTrans.TransDate = systemDateGet();
jourTrans.AccountType = LedgerJournalACType::Vend;
jourTrans.LedgerDimension = ledgerDim;
jourTrans.Txt = ‘Vendor payment journal demo’;
jourTrans.OffsetAccountType = LedgerJournalACType::Bank;
jourTrans.OffsetLedgerDimension = offsetLedgerDim;
jourTrans.AmountCurDebit = 1000;
jourTransData.create();
jourTable.insert();
ttsCommit;
info(strFmt(
“Journal ‘%1’ has been created”, jourTable.JournalNum));
/*LedgerJournalTable table;
ledgerjournalcheckpost post ;
;
table = LedgerJournalTable::find(“JB0000191”);
post = LedgerJournalCheckPost::newLedgerJournalTable(table,true,true);

// post = new LedgerJournalcheckPost::newLedgerJournalTable(table,NoYes::Yes,NoYes::Yes);
post.run();
info(“Done”);*/

}

Yes.

Hi Kranthi,
Thanks for your help. I have done below code -

AxLedgerJournalTable _JournalTable;
LedgerJournalTable _LedgerJournalTable;
LedgerJournalTrans _LedgerJournalTrans;
GeneralJournalAccountEntry _GeneralJournalAccountEntry, _GeneralJournalAccountEntry1;
GeneralJournalEntry _GeneralJournalEntry;
NoYes _reverseSign;
;

if (Box::yesNo("@SYS4003612",DialogButton::Yes) == DialogButton::Yes)
{
_JournalTable = new AxLedgerJournalTable();
_JournalTable.parmJournalName(“Normal_CSC”);
_JournalTable.save();
info(strFmt("Journal No %1 ",_JournalTable.ledgerJournalTable().JournalNum));

select _GeneralJournalAccountEntry where _GeneralJournalAccountEntry.PaymentReference == ‘01417286’;
select _GeneralJournalEntry where _GeneralJournalEntry.RecId == _GeneralJournalAccountEntry.GeneralJournalEntry;
_reverseSign = NoYes::Yes;
while select _GeneralJournalAccountEntry where _GeneralJournalAccountEntry.createdTransactionId == _GeneralJournalEntry.createdTransactionId
{
_LedgerJournalTrans.initValue();
_LedgerJournalTrans.JournalNum = _JournalTable.ledgerJournalTable().JournalNum;
_LedgerJournalTrans.Approved = NoYes::Yes;
_LedgerJournalTrans.Approver = HcmWorker::userId2Worker(curUserId());
_LedgerJournalTrans.Invisible = NoYes::No;
_LedgerJournalTrans.Transferred = NoYes::No;
_LedgerJournalTrans.TransDate = _GeneralJournalEntry.AccountingDate;
_LedgerJournalTrans.Company = curext();
//_LedgerJournalTrans.Voucher = new JournalVoucherNum(JournalTableData::newTable(_LedgerJournalTable)).getNew(true);
_LedgerJournalTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimFromLedgerDim(_GeneralJournalAccountEntry.LedgerDimension));
_LedgerJournalTrans.Txt = _GeneralJournalEntry.SubledgerVoucher;
_LedgerJournalTrans.TransactionType = _GeneralJournalEntry.JournalCategory;
_LedgerJournalTrans.CurrencyCode = _GeneralJournalAccountEntry.TransactionCurrencyCode;
_LedgerJournalTrans.ExchRate = _GeneralJournalAccountEntry.getAccountingExchangeRate();
if (_GeneralJournalAccountEntry.IsCorrection)
{
if(_GeneralJournalAccountEntry.AccountingCurrencyAmount < 0 )
{
_LedgerJournalTrans.AmountCurDebit = _reverseSign ? - _GeneralJournalAccountEntry.TransactionCurrencyAmount : _GeneralJournalAccountEntry.TransactionCurrencyAmount;
}
else
{
_LedgerJournalTrans.AmountCurCredit = _reverseSign ? _GeneralJournalAccountEntry.TransactionCurrencyAmount : -_GeneralJournalAccountEntry.TransactionCurrencyAmount;
}
}
else
{
if(_GeneralJournalAccountEntry.AccountingCurrencyAmount < 0)
{
_LedgerJournalTrans.AmountCurCredit = _reverseSign ? _GeneralJournalAccountEntry.TransactionCurrencyAmount : -_GeneralJournalAccountEntry.TransactionCurrencyAmount;
}
else
{
_LedgerJournalTrans.AmountCurDebit = _reverseSign ? -_GeneralJournalAccountEntry.TransactionCurrencyAmount : _GeneralJournalAccountEntry.TransactionCurrencyAmount;
}
}

if (_reverseSign)
{
_LedgerJournalTrans.Qty = -_GeneralJournalAccountEntry.Quantity;
}
else
{
_LedgerJournalTrans.Qty = _GeneralJournalAccountEntry.Quantity;
}

_LedgerJournalTrans.insert();
}
}
info(strFmt("Journal No %1 ",_LedgerJournalTrans.Voucher));

Above code is working fine. Problem is , it’s nor creating voucher no. How to create voucher no in lines? Please help.