Skip to main content

Notifications

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

Error on updating field in PriceDiscActual form extension

(0) ShareShare
ReportReport
Posted on by 27

Good morning,

I've got a question about an error that I get when trying to update some value in the PriceDiscActual form.

My goal: to set the "Discount percentage 1" value with a custom calculated value.

I thought it would be as simple as this (simplified version):

[ExtensionOf(formStr(PriceDiscActual))]
final class PriceDiscActual_FV_Extension
{
    void findPriceAgreement()
    {
        next findPriceAgreement();

        this.percent1 = 0.99;
    }
}

However, this gives me a runtime error "Invalid cast from 'System.Decimal' to 'Dynamics.AX.Application.Forms.PriceDiscActual'."

If I try to do the same logic with the salesLineDisc field it works fine as expected.

Can anyone give me some hints why the percent1 field is different from the salesLineDisc field? And how I can achieve my goal of setting the percent1 field with a custom value?

  • FV@E Profile Picture
    FV@E 27 on at
    RE: Error on updating field in PriceDiscActual form extension

    Yes I had already tried that as well. If I do that, the build already fails:

    pastedimage1683632995656v1.png

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Error on updating field in PriceDiscActual form extension

    pastedimage1683632337795v1.png

    Have you tried giving like above?

    like, percent1 = 0.99; without this?

  • FV@E Profile Picture
    FV@E 27 on at
    RE: Error on updating field in PriceDiscActual form extension

    Of course. When I reach the line "this.percent1 = 0.99" I get the error that I mentioned in my first post.

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Error on updating field in PriceDiscActual form extension

    Have you debugged your code?

  • FV@E Profile Picture
    FV@E 27 on at
    RE: Error on updating field in PriceDiscActual form extension

    Thank you for answering Bharani Preetham Peraka . Unfortunately that doesn't really help me. As you can see in my example, I am already creating a COC extension. The extension is called correctly. My question is: why can I update the salesLineDisc field in my extension, but not the percent1 field?

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Error on updating field in PriceDiscActual form extension

    To give a default value, you have to use init() or initvalue() methods at form ds and table methods. This gives a default value form is run.

    If you want to override the value, then you have to write a COC or event handler when insert is happened.

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,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans