web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to get Journal Lines Data into a Map object

(1) ShareShare
ReportReport
Posted on by 89

Hi, 

I have a requirement to automatically post inventory journals but I must extract the line data from the journal at the time of posting. The map object I have defined and use in a next method takes an Enum (inicating the line is a credit or a debit) and a Int64 (the ledger dimension for that line). Currently, the code below works for when there is only one line in the journal, but when there is two (or more) the map starts mixing and matching values (for instance, the ledger dimension will be associated with a debit line but will read as a credit in the code). Additionally, the map gets updated and replaced when it is ran more than 2 times which happens when there is more than one line. Please refer to my code below:

public void reverseFinancialVouchers(JournalTransList _transList)
{
GeneralJournalAccountEntry reverseFinancialEntry;
GeneralJournalAccountEntry origAccountEntry;
GeneralJournalEntry origJournalEntry;
Map journalMap;


if (_transList.first())
{
do
{
JournalTransData transData = _transList.journalTransData();
Common record = transData.journalTrans();

journalMap = new Map(Types::Enum, Types::Int64);

if (record.TableId == tableNum(InventJournalTrans))
{
InventJournalTrans journalTrans = record as InventJournalTrans;

select firstonly origJournalEntry where
origJournalEntry.SubledgerVoucher == journalTrans.Voucher &&
origJournalEntry.SubledgerVoucherDataAreaId == journalTrans.DataAreaId;

//ts
itemIdForLookup = journalTrans.ItemId;
//ts

while select origAccountEntry where origAccountEntry.GeneralJournalEntry == origJournalEntry.RecId
{
reverseFinancialEntry.data(origAccountEntry);
reverseFinancialEntry.AccountingCurrencyAmount = -(origAccountEntry.AccountingCurrencyAmount);
reverseFinancialEntry.TransactionCurrencyAmount = -(origAccountEntry.TransactionCurrencyAmount);
reverseFinancialEntry.ReportingCurrencyAmount = -(origAccountEntry.ReportingCurrencyAmount);

if (origAccountEntry.IsCredit == NoYes::No)
{
reverseFinancialEntry.IsCredit = NoYes::Yes;
reverseFinancialEntry.PostingType = LedgerPostingType::InventProfit;
}
else
{
reverseFinancialEntry.IsCredit = NoYes::No;
reverseFinancialEntry.PostingType = LedgerPostingType::InventReceipt;
//ts
postingTypeForLookup = origAccountEntry.PostingType;
origMainAccount = origAccountEntry.MainAccount;
//JournalCheckPostLedger::fetchBudgetControlAccount();
//ts

}

reverseFinancialEntry.doinsert();
journalMap.add(origAccountEntry.IsCredit, origAccountEntry.LedgerDimension);

}
this.createAndPostFinancialJournal(journalTrans, journalMap);
}
}
while (_transList.next());
}
}

I have the same question (0)
  • tristansenk99 Profile Picture
    89 on at

    The above code is meant to reverse the journal lines in the financial voucher. It works for one line, but when there is two lines it doubles the required number of reversals.

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    First of all, let me re-post your code with line indentation, because it's very difficult to read without it. Next time, please don't forget to use Insert > Code (in the rich formatting view).

    public void reverseFinancialVouchers(JournalTransList _transList)
    {
    	GeneralJournalAccountEntry reverseFinancialEntry;
    	GeneralJournalAccountEntry origAccountEntry;
    	GeneralJournalEntry origJournalEntry;
    	Map journalMap;
    
    	if (_transList.first())
    	{
    		do
    		{
    			JournalTransData transData = _transList.journalTransData();
    			Common record = transData.journalTrans();
    
    			journalMap = new Map(Types::Enum, Types::Int64);
    
    			if (record.TableId == tableNum(InventJournalTrans))
    			{
    				InventJournalTrans journalTrans = record as InventJournalTrans;
    
    				select firstonly origJournalEntry where
    				origJournalEntry.SubledgerVoucher == journalTrans.Voucher &&
    				origJournalEntry.SubledgerVoucherDataAreaId == journalTrans.DataAreaId;
    
    				itemIdForLookup = journalTrans.ItemId;
    
    				while select origAccountEntry where origAccountEntry.GeneralJournalEntry == origJournalEntry.RecId
    				{
    					reverseFinancialEntry.data(origAccountEntry);
    					reverseFinancialEntry.AccountingCurrencyAmount = -(origAccountEntry.AccountingCurrencyAmount);
    					reverseFinancialEntry.TransactionCurrencyAmount = -(origAccountEntry.TransactionCurrencyAmount);
    					reverseFinancialEntry.ReportingCurrencyAmount = -(origAccountEntry.ReportingCurrencyAmount);
    
    					if (origAccountEntry.IsCredit == NoYes::No)
    					{
    						reverseFinancialEntry.IsCredit = NoYes::Yes;
    						reverseFinancialEntry.PostingType = LedgerPostingType::InventProfit;
    					}
    					else
    					{
    						reverseFinancialEntry.IsCredit = NoYes::No;
    						reverseFinancialEntry.PostingType = LedgerPostingType::InventReceipt;
    						postingTypeForLookup = origAccountEntry.PostingType;
    						origMainAccount = origAccountEntry.MainAccount;
    					}
    
    					reverseFinancialEntry.doinsert();
    					journalMap.add(origAccountEntry.IsCredit, origAccountEntry.LedgerDimension);
    				}
    				this.createAndPostFinancialJournal(journalTrans, journalMap);
    			}
    		}
    		while (_transList.next());
    	}
    }

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Also, let me simplify your code a bit.

    public void reverseFinancialVouchers(JournalTransList _transList)
    {
    	if (!_transList.first())
    	{
    		return;
    	}
    	
    	do
    	{
    		JournalTransData transData = _transList.journalTransData();
    		InventJournalTrans journalTrans = transData.journalTrans() as InventJournalTrans;
    		Map journalMap = new Map(Types::Enum, Types::Int64);		
    
    		if (journalTrans)
    		{
    			GeneralJournalAccountEntry reverseFinancialEntry;
    			GeneralJournalAccountEntry origAccountEntry;
    			GeneralJournalEntry origJournalEntry;
    
    			while select origAccountEntry
    				where origAccountEntry.GeneralJournalEntry == origJournalEntry.RecId				
    				exists join origJournalEntry
    					where origJournalEntry.RecId == origAccountEntry.GeneralJournalEntry
    					   && origJournalEntry.SubledgerVoucher == journalTrans.Voucher
    				       && origJournalEntry.SubledgerVoucherDataAreaId == journalTrans.DataAreaId;
    			{
    				reverseFinancialEntry.data(origAccountEntry);
    				reverseFinancialEntry.AccountingCurrencyAmount = -origAccountEntry.AccountingCurrencyAmount;
    				reverseFinancialEntry.TransactionCurrencyAmount = -origAccountEntry.TransactionCurrencyAmount;
    				reverseFinancialEntry.ReportingCurrencyAmount = -origAccountEntry.ReportingCurrencyAmount;
    
    				if (origAccountEntry.IsCredit == NoYes::No)
    				{
    					reverseFinancialEntry.IsCredit = NoYes::Yes;
    					reverseFinancialEntry.PostingType = LedgerPostingType::InventProfit;
    				}
    				else
    				{
    					reverseFinancialEntry.IsCredit = NoYes::No;
    					reverseFinancialEntry.PostingType = LedgerPostingType::InventReceipt;
    					postingTypeForLookup = origAccountEntry.PostingType;
    					origMainAccount = origAccountEntry.MainAccount;
    				}
    
    				reverseFinancialEntry.doInsert();
    				journalMap.add(origAccountEntry.IsCredit, origAccountEntry.LedgerDimension);
    			}
    			this.createAndPostFinancialJournal(journalTrans, journalMap);
    		}
    	}
    	while (_transList.next());
    }

    Are you saying that wrong values get stored in the map? I see that you always store LedgerDimension of the last line (for credit and debit), isn't it the problem? If you agree that this is wrong and you don't know how to fix it, please explain what logic you want to get.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans