I need advice how to automate the General Ledgers "Load ledger transaction" process in X++.
(General Journal > Lines > Functions > Load ledger transactions) with params:
I have created an PostEventHandler which will perform this operation for the voucher it is handling in the project's elimination process based on the checkbox selection. In the EventHandler I have created a new Ledger journal using the AXLedgerJournalTable class and now I need to create the inverted transaction lines for the voucher and post it.
I've been trying to mimic of the Load process starting from the LedgerJournaGetTrans.main(), but I end up recreating about everything in it in the event handler and the code is getting quite messy. Is there better way to do this? Can I use some other classes like TransactionReversal_Ledger for this?
*This post is locked for comments
Hey,
Sorry about delay on the reply as I was in summer holidays when you posted this request.
In iNNParmReverseSign(NoYes::Yes) -method I just SET -method for the parameter, because I cannot access it directly as the class is Private.
If I remember it correctly it was something like this:
Public class iNNParmReverseSign(NoYes _reversing)
{
// set the new value
ReverseSign = _reversesing;
}
Hi Teemu, Thank you to share this blog. Can you share the method "iNNParmReverseSign" and others? because they are not system method. Thank you very much!
Got it solved my self. Heres my succesfully tested solution. I did not post new parm-classes as those are trivial.
public static void OnActionProjControlPeriodEli_Handler(XppPrePostArgs _xppPrePostArgs)
{
Object object;
ProjControlPeriodEliminate projControlPeriodEliminate;
ProjControlPeriodTable projControlPeriodTable;
AxLedgerJournalTable axLedgerJournalTable ;
LedgerJournalGetTrans ledgerJournalGetTrans;
QueryRun queryRun;
QueryBuildDataSource queryDataSource;
QueryBuildRange queryBuildRange;
ledgerJournalCheckPost ledgerJournalCheckPost;
// Get the dialog settings
object = _xppPrePostArgs.getThis();
if(object is projControlPeriod)
{
projControlPeriodEliminate = object as projControlPeriodEliminate;
// If user needs to reverse the voucher in elimination.
if(ProjControlPeriodEliminate.iNNParmPostEstimateReversalVoucher() == NoYes::Yes)
{
// Creates a new ledger journal
axLedgerJournalTable = new AxLedgerJournalTable();
axLedgerJournalTable.parmJournalName(projControlPeriodEliminate.iNNParmLedgerJournalNameId());
axLedgerJournalTable.save();
info(strFmt("A new ledger journal %1 created with journal name %2", axLedgerJournalTable.ledgerJournalTable().JournalNum,
projControlPeriodEliminate.iNNParmLedgerJournalNameId()));
// Only posted project lines needs to be reversed
while select projControlPeriodTable
where projControlPeriodTable.PeriodStatus == projControlPeriodStatus::Posted
&& projControlPeriodTable.ProjId == projControlPeriodEliminate.parmProjWIPProjId()
{
// Load the invert transaction
ledgerJournalGetTrans = LedgerJournalGetTrans::INNnewLedgerJournalTable(axLedgerJournalTable.ledgerJournalTable());
// Override parameters
ledgerJournalGetTrans.iNNParmReverseSign(NoYes::Yes); // We want always to reverse the journals
// We want always create new vouchers for inverted
ledgerJournalGetTrans.iNNParmLedgerGetVoucherMethod(LedgerGetVoucherMethod::NewPrVoucher);
// We need to build the dialog query by hand
queryRun = ledgerJournalGetTrans.iNNParmQueryRun();
queryDataSource = queryRun.query().dataSourceTable(tablenum(GeneralJournalEntry));
queryBuildRange = queryDataSource.addRange(fieldNum(GeneralJournalEntry, subLedgerVoucher));
queryBuildRange.value(queryValue(projControlPeriodTable.VoucherPosted)); // We need to reverse the voucher in hand.
ledgerJournalGetTrans.run();
info(strFmt("Inverted lines created against voucher %1 in journal %2.",projControlPeriodTable.VoucherPosted ,
LedgerJournalGetTrans.parmLedgerJournalId()));
}
// Posting the lines
if(LedgerJournalGetTrans)
{
ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(axLedgerJournalTable.ledgerJournalTable(), NoYes::Yes);
ledgerJournalCheckPost.run();
}
}
}
}
AND THE NEW CONSTRUCT CLASS:
// A construct class without dialog handling.
public static LedgerJournalGetTrans iNNNewLedgerJournalTable(LedgerJournalTable _ledgerJournalTable)
{
LedgerJournalGetTrans ledgerJournalGetTrans;
ledgerJournalGetTrans = new LedgerJournalGetTrans();
ledgerJournalGetTrans.init();
ledgerJournalGetTrans.parmLedgerJournalId(_ledgerJournalTable.JournalNum);
return ledgerJournalGetTrans;
}
Thanks Ludwig. First time using this, so was not sure how to use the tags. Tags corrected now. Our Customer is using parts of the AX as a service for their own customers so this is not normal AX-business case.
Hi Teemu, What is the Business reason for the adjustment you want to make? Probably add /Change tags if possible as the development experts in the community might not easily find your post if you classify it as "financial Management" question. Ludwig
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156