Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Call method of button ...
Finance forum

Call method of button event handler

(0) ShareShare
ReportReport
Posted on by 452

HI All,

 I need to execute a custom code based on a standard method code result, the standard method is on a button control in a form,

Public clicked()

{

super()

buffer.method();

}

I have created a clicked event handler in an extension

[FormControlEventHandler(formControlStr(HcmWorker, ArgsExampleButton), FormControlEventType::Clicked)]
public static void ArgsExampleButton_OnClicked(FormControl sender, FormControlEventArgs e)
{

    //mycustomermethod();
}

not what i want to achieve is , my custom code to be triggered based on the successful execution of  buffer.clicked() in the standard clicked method. since the buffer.code does not return anything i thought of using error handling to achieve this,

try {

buffer.method();

}

exception::error or Waring

{

give the same error/or warning message the method gives.

}

else 

{

//execute my code.

}

. how do i call the method already called in base form clicked.

thanks. 

  • Karunakaran nainar Profile Picture
    452 on at
    RE: Call method of button event handler

    Hi Nikolaos and Sumit,

    Thanks for your responses, i tried to search on the suggesged lines I got the below link were we can use try catch on Next() call.

    docs.microsoft.com/.../method-wrapping-coc

    thanks,

  • Verified answer
    Sumit Loya Profile Picture
    2,230 on at
    RE: Call method of button event handler

    Hi Karunakaran,

    You can either create a CoC for clicked method of form control as suggested by Nikolaos or you can also create CoC of the buffer.method() if it is possible and use next() in try-catch block. Please note that latest versions of D365 allow next call to be in try-catch block.

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Call method of button event handler

    I'm not sure if I understand your requirement.

    Anyway your event handler code will always be executed after the super() call of the clicked method of the standard button. This is because the "Clicked" event is fired in/after the super() call.

    So, you can't conditionally run your event handler method, based on what happens in buffer.method().

    However I think you could use Chain of Command on the clicked method, and be able to run your code only after the whole clicked method has been executed. And then you could even try to add a try catch around the "next" call.

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 > Finance forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans