Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

What is cache enable for, in function SpecTransManager Class function findByRef

(0) ShareShare
ReportReport
Posted on by 305

Hi guys,

I'm creating some program to create Customer Payment Journal through X   whereby I need to find amount to settle from CustTransOpen table information. The code is like : 

CustVendOpenTransManager  manager = CustVendOpenTransManager::construct(ledgerjournaltrans);

CustTransOpen       custTransOpen = CustTransOpen::findRefId(CustTrans::findFromInvoice(invoiceId,TempTable.CustAccount).RecId);
Amount              openAmountLeftforInvoice = manager.getSettleAmount(custTransOpen);

So the information I have to start with, are InvoiceId and Customer account. The idea is then look into CustTransOpen, and then from there I want to take info from table SpecTrans by using class CustVendOpenTransManager.

But it seems I can't get the amount from SpecTrans by using that particular function called getSettleAmount(custTransOpen); since inside it there is a function to get the SpecTrans by using FindByRef which I'm not sure why it is not retrieve any record, although I checked in SSMS, it has the record.

This is the getSettleAmount function : 

public AmountCur getSettleAmount(CustVendTransOpen _custVendTransOpen,
        boolean _includeFineAndInterest = true)
    {
        AmountCur settleAmount;
        AmountCur cashDiscAmountToTake;
        SpecTrans specTrans;
        // 
        AmountCur fineAmount;
        AmountCur interestAmount;
        // 

        specTrans = specTransManager.findByRef(_custVendTransOpen.company(), _custVendTransOpen.TableId, _custVendTransOpen.RecId);

        if (specTrans.RecId != 0)
        {
            // Get settle amount (Balance01) stored on associated SpecTrans record
            settleAmount = specTrans.Balance01;

            // 
            if (BrazilParameters::isEnabled() && _includeFineAndInterest == false)
            {
                // Retrieve last calculated fine and interest amounts
                fineAmount = this.getLastFineAmount_BR(_custVendTransOpen);
                interestAmount = this.getLastInterestAmount_BR(_custVendTransOpen);

                // Remove interest and fine
                settleAmount -= (fineAmount   interestAmount);
            }
            // 
        }
        else
        {
            // This amount includes the available discount
            cashDiscAmountToTake = this.determineCashDiscAmountToTake(_custVendTransOpen, true);

            settleAmount = this.determineSettleAmountIncludingCashDiscount(_custVendTransOpen, cashDiscAmountToTake, _includeFineAndInterest);
        }

        return settleAmount;
    }

And as we can see in above code, there is a function FindByRef from class SpecTransManager which is this one : 

public SpecTrans findByRef(CompanyId _refCompany, tableId _refTableId, RefRecId _refRecId)
    {
        SpecTrans foundSpecTrans;
        boolean inMissingCache = false;

        if (cacheEnabled)
        {
            // If cache is not initialized, initialize with all records here.
            if (cacheInitialized == false)
            {
                this.initCacheWithMarkedTransactions();
            }

            foundSpecTrans = specTransCache.get(_refCompany, _refTableId, _refRecId);

            if (foundSpecTrans.RecId == 0)
            {
                // Check if it is in the missing cache
                inMissingCache = specTransCache.inMissingCache(_refCompany, _refTableId, _refRecId);
            }
        }

        if (cacheEnabled == false || (foundSpecTrans.RecId == 0 && inMissingCache == false))
        {
            // Caching was not enabled or it was not found in either cache, find in database
            foundSpecTrans = SpecTrans::find(specCompany, specTableId, specRecId, _refCompany, _refTableId, _refRecId);

            if (cacheEnabled == true)
            {
                if (foundSpecTrans.RecId != 0)
                {
                    // Add record to cache
                    specTransCache.add(foundSpecTrans);
                }
                else
                {
                    // Add reference to missing cache
                    specTransCache.addAsMissing(_refCompany, _refTableId, _refRecId);
                }
            }
        }

        return foundSpecTrans;
    }

From here, I am lost, since I confirmed the parameter used is correct (refCompany, refTableID, refRecId). All these three parameter are correct, and I checked in SSMS the record exists.

What I'm confuse is that chachEnabled thing, also there are bunch of logic "checking" about this cache, which I have no idea what and why.

Btw, for these 2 function, CustVendOpenTransManager.GetSettleAmount() and SpecTransManager.FindByRef(), are standard with no customization.

Anyone can help to enlighten me, what is this cache thing ? and why the result is empty although I have the record.

Thanks.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans