Hi,
Simply , How can I create and post Voucher using X++ code? Like in General Ledger>>Inquiries>>Voucher Transactions form, many thanks.
Regards,
Hisham.
Hi,
Simply , How can I create and post Voucher using X++ code? Like in General Ledger>>Inquiries>>Voucher Transactions form, many thanks.
Regards,
Hisham.
Have you read Posting to the Ledger?
yes , but what do u mean ?i need for Voucher to post direct from my form instead of create ledger and post from general ledger form,do u get it?
regards,
hisham
The document describes the programming interface, i.e. which class you have to use and how. For example, you can read there:
LedgerVoucherObject::newVoucher
The static method creates a new ledgerVoucherObject representing a new voucher. Depending on the transaction type a number of parm methods may be called to set voucher values.
For more real-life examples, just use cross-references on these classes and methods.
What else are you looking for?
Dear Martin,
Kindly ,you sent me a very helpful and rich document i will read it and back to you for any clarification
, what does Cross - reference do ? , please provide me with an info about its job , your help highly appreciated ,thanks a lot .
Regards,
Hisham.
Hi Hisham,
I run into the same problem you are facing about last year. I wonder have you finish the voucher posting?
I’ve googled about posting voucher using x++ but can’t find any helpful reference. Can you give me any reference to posting voucher using x++ code?
Thank you very much,
Esther
Hi,
FYI , Journal contents of voucher or number of voucher so you can create General Journal using the code like in below
static void VendPaymJournalCreate(Args _args)
{
LedgerJournalTable jourTable;
LedgerJournalTrans jourTrans;
LedgerJournalTableData jourTableData;
LedgerJournalTransData jourTransData;
LedgerJournalStatic jourStatic;
DimensionDynamicAccount ledgerDim;
DimensionDynamicAccount offsetLedgerDim;
ttsBegin;
ledgerDim = DimensionStorage::getDynamicAccount(
‘1001’,
LedgerJournalACType::Vend);
offsetLedgerDim = DimensionStorage::getDynamicAccount(
‘USA OPER’,
LedgerJournalACType::Bank);
jourTableData = JournalTableData::newTable(jourTable);
jourTable.JournalNum = jourTableData.nextJournalId();
jourTable.JournalType = LedgerJournalType::Payment;
jourTable.JournalName = ‘APPay’;
jourTableData.initFromJournalName(
LedgerJournalName::find(jourTable.JournalName));
jourStatic = jourTableData.journalStatic();
jourTransData = jourStatic.newJournalTransData(
jourTrans,
jourTableData);
jourTransData.initFromJournalTable();
jourTrans.CurrencyCode = ‘USD’;
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));
}
→ then you should make your post via this code
static void LedgerJournalPost(Args _args)
{
LedgerJournalCheckPost jourPost;
LedgerJournalTable jourTable;
jourTable = LedgerJournalTable::find(‘000420_010’);
jourPost = LedgerJournalCheckPost::newLedgerJournalTable(
jourTable,
NoYes::Yes);
jourPost.run();
}
you can change type of journal depend on your business needs
try it , waiting for your reply for any other support
Thanks.
Hisham
Hisham
i am getting error at this line.
LedgerJournalAC ledgerAccount= ‘1000’;
ledgerDim = DimensionStorage::getDynamicAccount(ledgerAccount,LedgerJournalACType::Ledger);
this is the error i am getting
Function DimensionHierarchy::getHierarchyIdByHierarchyType has been incorrectly called.
any help please.
Hi Hisham,
Thank you for the code, I was getting error that class LedgerJournalTransData is not found, so I googled and found out that the code you give me is from the book Microsoft Dynamics AX 2012 Development Cookbook
I read the book and try the code, and it run perfectly.
Thank you very much Hisham.
Regards,
Esther
Esther,
i am working in AX 2012 not 2009 ,
ledgerDim = DimensionStorage::getDynamicAccount(ledgerAccount,LedgerJournalACType::Ledger); throws error for your info.
did you try this in 2009 or 2012?
Hi eswar,
I try this in AX 2012. For AX 2009, maybe the code will be slightly different.
found the problem. sumit loya has explained the same in his blog.
You can use method getDynamicAccount instead of getDefaultAccountForMainAccount to get the LedgerDimension for non-ledger accounts.
i am trying to use getDynamicsAccount for LedgerDimension. which is wrong , if its ledger use getDefaultAccountForMainAccount.
i am running into other issues , but this is clear. hope others might find this helpful
Dear Esther,
I am creating ledger to ledger invoice journal
i have problem in accessing the ledger account and ledger offset account can u help me,how to access the ledger account ,offset account .
and i am using ax 2012
This is my run method
public void run()
{
AxLedgerJournalTable header = new AxLedgerJournalTable();
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTable ledgerJournalTable;
LedgerJournalName ledgerJournalName;
;
//Header Table
header.parmJournalType(LedgerJournalType::VendInvoiceRegister);//This code is mention the type of the code(ap invoice register)
header.parmJournalName(“APInv”);
header.save();
//line table
trans.parmTransDate(today());
trans.parmjournalnum(header.ledgerjournaltable().journalnum);
info(header.ledgerjournaltable().journalnum);
trans.parmJournalNum(header.ledgerJournalTable().JournalNum);
// trans.parmVoucher(numberseq.num());
trans.parminvoice(“Ledger payment”);
trans.parmcurrencycode(“USD”);
trans.parmtxt(“Check”);
trans.parmamountcurcredit(100);
trans.parmoffsetaccounttype(LedgerJournalACType::Ledger);
//trans.parmOffsetAccountType(trans.lookupAccountNum(_formStringControl));
//trans.parmOffsetLedgerDimension(;
trans.save();
}
can you please tell me how to create multiple vouchers for different lines in journal using X++ code?