A year ago, I did some customization, where ledger entries are done with X++ code. Now client wants Reverse ledger entries. As per logic reverse ledger entries has only difference is debit amount will be credit amount and versa vise. With X++ code 80 percent of these entries are successful, But 20 percent were fail with following Error.
Voucher not Specified as of …
So what is solution. I found only solution to read next voucher from sequence number and assign to ledger trans before posting it. I used following code snippet to get and set next voucher
select firstOnly numSeqTable
where numSeqTable.RecId == ledgerJournalName.NumberSequenceTable;
if (numSeqTable)
{
numberseq = numberseq::newGetVoucherFromCode(numSeqTable.NumberSequence);
trans.parmVoucher( numberseq.voucher());
}
Now customization works perfectly fine.