Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to cancel super call of a button click event through extension?

(0) ShareShare
ReportReport
Posted on by 75

I want to add a check to the click event of a button, when check failed, I want to cancel the super call, how to do it?

I have tried to use FormControlCancelableSuperEventArgs and FormControlCancelEventArgs in event handler of clicking event, but both of them return null.

Below is my test code.

[FormControlEventHandler(formControlStr(LedgerJournalTable, Approve), FormControlEventType::Clicking)]
public static void Approve_OnClicking(FormControl sender, FormControlEventArgs e)
{
    FormControlCancelEventArgs	ce = e as FormControlCancelEventArgs;  // ce returns null
    FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;  // ce returns null too
}

I know I can complete it by throw exception, but I think it is not a official way.

So how can I cancel the super call by a official way?

  • Martin Dráb Profile Picture
    231,837 Most Valuable Professional on at
    RE: How to cancel super call of a button click event through extension?

    As mentioned, your design can't be implemented. Throwing an exception is a feasible workaround, but not the only one. For example, maybe you could check the condition in active() and disable the button if it's not met. Or maybe you could put the validation to the object called by the button.

  • bjdchw Profile Picture
    75 on at
    RE: How to cancel super call of a button click event through extension?

    Hi Will Wu,

    Thank you for you reply.

    Call to 'next' should be done only once and unconditionally.

    So we can't use a if-else block to skip super() call.

  • WillWU Profile Picture
    22,352 on at
    RE: How to cancel super call of a button click event through extension?

    Hi bjdchw,

    FormControlCancelableSuperEventArgs would be applicable to certain form control events, one of them is the onLookup event. It does not support the onclick event of formcontrol.

    You could try to use a if-else block to skip super() call. It will be much better than throwing an exception.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans