Skip to main content

Notifications

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,

  • Suggested answer
    VoltesDev Profile Picture
    VoltesDev on at
    RE: Unable to cast object type TaxRegulation to TaxRegulationDetail

    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,

  • VoltesDev Profile Picture
    VoltesDev on at
    RE: Unable to cast object type TaxRegulation to TaxRegulationDetail

    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,

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Unable to cast object type TaxRegulation to TaxRegulationDetail

    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
    VoltesDev on at
    RE: Unable to cast object type TaxRegulation to TaxRegulationDetail

    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,

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Unable to cast object type TaxRegulation to TaxRegulationDetail

    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?

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans