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;
}