Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Access tax trans fields
Finance forum
Suggested answer

Access tax trans fields

Posted on by 252
Hi,

If you go to "custInvoiceJour" form, then click on "posted sales tax". There is a tab called "Amount" and inside it there is a field on the form called "Origin"
This is a display method on the form data sources methods.


Now I have another class, where I have access to the invoiceId, but i would like to get this value from taxTrans
I can see the relation between custInvoiceJour and taxTrans



but as you can see, that there is logic in the display method that could show the sign as positive or negative, and i can't call this method in my class because it's private and it's on form datasource.
is the only thing i can do is to repeat the logic inside the display method again in my class? or what should i do?
  • DELDYN Profile Picture
    DELDYN 252 on at
    Access tax trans fields
    Hi Jonas,

    So do you mean this method can't be used?

    this is what i did at first just like you mentioned, but i wanted a standard method in case in the future this will change

    but in this case I had to do two selects to the database based on my logic (as i need to sum tax base amount based on tax value
  • Access tax trans fields

    I haven't tested the tax method out (need to fix my development environment, so going off memory), but I don't think it works against the journal header (or journals at all, only order lines and free text lines) judging by how it's used in the standard application.

    Sleeping on it, the best bet might be to just replicate the display method, since it's fairly simple if we disregard any country/region functionality. It might not be needed in your case.

    If we examine the form display method, it contains the following code (as of 10.0.40). I have blacked out any country/region functionality we don't care about:

    display TaxBase displayTaxBaseAmount(TaxTrans _taxTrans)
    {
        //<GEECZ>
        changeDisplaySign = this.doChangeDisplaySign(_taxTrans);
        //</GEECZ>
        return _taxTrans.TaxBaseAmount * this.taxChangeDisplaySign(_taxTrans.TaxDirection, _taxTrans.ReverseCharge_W, Tax::changeSignForReverseCharge(_taxTrans));
    }
    

    The method taxChangeDisplaySign contains the following code:

    private int taxChangeDisplaySign(TaxDirection _taxDirection, TaxReverseCharge _taxReverseCharge = NoYes::No, boolean _changeSignForReverseCharge = true)
    {
        if (changeDisplaySign && (_taxReverseCharge == NoYes::No || _changeSignForReverseCharge))
        {
            return Tax::changeDisplaySign(_taxDirection);
        }
        else
        {
            return 1;
        }
    }
    

    So, looking at the code, we can see that:

    • It's taking _taxTrans.TaxBaseAmount.
    • Based on the value of _taxTrans.TaxDirection, and a call to Tax::changeSignForReverseCharge(_taxTrans), it will flip the sign.

    I think this logic should be easy to implement. Let me know if you need an example or if I should test the Tax method.

     
     
  • DELDYN Profile Picture
    DELDYN 252 on at
    Access tax trans fields
    Hi Jonas,

    Maybe the first line in the display method is related to CZ

    But the 2nd line is not
    this.taxChangeDisplaySign(_taxTrans.TaxDirection, _taxTrans.ReverseCharge_W, Tax::changeSignForReverseCharge(_taxTrans));

    if now you want me to replace the whole logic in the display method with the code below, the change display sign variable should be true right?
            CustInvoiceJour custInvoiceJour;
            select custInvoiceJour where custInvoiceJour.InvoiceId == 'xxxx';
            TaxBase taxBase = tax.getOriginForSourceLine(custInvoiceJour.TableId, custInvoiceJour.RecId, true);

     currently taxBase is 0 even though it should be 1000, why?
    and custInvoiceJour is returning data -- so i have no issue here

    shall i pass other values?
  • Suggested answer
    Access tax trans fields
    Hi DELDYN,  
    My advice is to avoid replicating the logic of the display method and use Tax.getOriginForSourceLine instead.  

    It’s always better to try to find a clean interface and use that if possible. This way, you can be sure that any changes in logic that Microsoft might introduce will also work in your method.
     
    The logic in the form is fairly simple though, if you need to use it; it’s "just" some logic to handle specific country/region scenarios in CZ.
     
     

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans