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, ...
Suggested Answer

Unable to cast object type TaxRegulation to TaxRegulationDetail

(0) ShareShare
ReportReport
Posted on by

Hi guys,

I'm trying to make use of class called "TaxRegulation"

TaxRegulationDetail taxRegulationDetail = TaxRegulation::newTaxRegulation(salesTotals.tax());

TmpTaxRegulation    tmpTaxRegulationDetail = taxRegulationDetail.tmpTaxRegulationDetail();

but currently hit error like this : 

pastedimage1681699798872v1.png

The error as in the picture is hit on the 1sts line, may I know how to resolve this ?

The intention is to get TaxRegulation data based on sales line.

Thanks,

I have the same question (0)
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Here you have created the class object but you are calling a different class. It should be like,

    ClassName classObj = ClassName::method name(param1);

    Similarly for second line also. But can you tell us why you are calling another class here?

  • VoltesDev Profile Picture
    on at

    Hi Bharani,

    Yes, sorry, I realized this just now, then I'm changing it to this : 

    TaxRegulation taxRegulation = TaxRegulation::newTaxRegulation(salesTotals.tax());
    TaxRegulationDetail taxRegulationDetail = taxRegulation as TaxRegulationDetail;
    TmpTaxRegulation    tmpTaxRegulationDetail = taxRegulationDetail.tmpTaxRegulationDetail();

    But it looks it is not the correct way either, since I then have error on the 3rd line

    pastedimage1681701075468v1.png

    Can you help me to understand the error and how to use it correctly ?

    The TaxRegulationDetail is an extend class of TaxRegulation.

    Thanks,

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Your code seems to be correct. This error comes when the object does not have any value. Can you check if salesTotals have a buffer and also in the tax regulation?

  • VoltesDev Profile Picture
    on at

    Hi,

    The SalesTotal have a buffer as well as TaxRegulation. 

    As in this screenshot : 

    pastedimage1681705918187v2.png

    But I think the "taxRegulationDetail" is not correct/working as it is still null.

    I tried to take a look at class TaxRegulationDetail, and the remarks says it "manages tax adjustments at the invoice line detail level", does it means this class only handle data at Invoice level ? 

    As my process, Sales Order, is not invoiced yet. 

    For the class TaxRegulation itself actually also have method "taxRegulationDetail" but it is set to Null ->

    pastedimage1681706180721v3.png

    How to get data per Sales Line exactly ?

    Thanks,

  • Suggested answer
    VoltesDev Profile Picture
    on at

    This is solved. After learning the class TaxRegulation already can handle the selection for TaxRegulationDetail based on AR - Parameters, Ledger & sales tax -> Enable tax adjustment in detailed mode.

    When it is selected, TaxRegulation will be cast as TaxRegulationDetail.

    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

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
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans