Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Access tax trans fields

Posted on by 304
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?
  • Access tax trans fields
    I meant that it's worth looking for standard methods in the tax engine and, if one is available, use that. In your specific example, none might be available, as you are trying to get the base from the posted journal (Customer invoices, based on the "CustInvoiceJour" form you mention).
     
    Looking at the attached code, your logic appears to be flawed and will most likely not work.
    You summarize "TaxBaseAmount," grouped by the amount field "TaxValue." That select statement cannot return a RecId value for later use. Grouping on TaxValue makes little use in this context.
     
    I suggest testing your logic first, making a "While Select" on TaxTrans for all fields, performing the sign manipulation, and then appending that value to a variable outside your loop. After you have made that work, then you can look at summarizing and grouping to improve performance.
  • DELDYN Profile Picture
    DELDYN 304 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 304 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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans