Skip to main content

Notifications

Dynamics 365 general forum

FormControlCancelableSuperEventArgs.CancelSuperCall() not cancelling menu item button in onclicked event handler

Posted on by 155

Hello, I have added a menu item button to a form extension. If the user clicks on it I need to check a condition and if it is not true then I want to display a message and prevent the display menu item form that the button references from opening. In my event handler class I have the onclicked event handler of the button and the following code.

if (svcCallTable.CustAccount == '') {
    throw error('You must select a customer account before adding new contacts!');
    FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;

       ce.CancelSuperCall();
}

The problem is that the called form still opens and the message displays on that form. I need to prevent the called form from opening and display the message on the caller form. How can I do that?

  • Jie G Profile Picture
    Jie G on at
    RE: FormControlCancelableSuperEventArgs.CancelSuperCall() not cancelling menu item button in onclicked event handler

    Hello Kurt Warner,

    Do you still have any issue on this thread? Would you please mark it as verified if it helps.

  • Suggested answer
    Jie G Profile Picture
    Jie G on at
    RE: FormControlCancelableSuperEventArgs.CancelSuperCall() not cancelling menu item button in onclicked event handler

    Hello Kurt Warner,

    This is because the code after "throw error" statement will not be executed.

    The throw statement should be used only if a piece of code cannot do what it is expected to do. The throw statement should not be used for more ordinary program flow control.

    So you can put the line of throw error('You must select a customer account before adding new contacts!') after CancelSuperCall( ), Or you can consider using the warning or info instead.

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 Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

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... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans