web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Event handler needed to call method from referred C# library using Menu Item Action

(0) ShareShare
ReportReport
Posted on by 40

I have written a simple C# library 

pastedimage1596725579584v1.png

In SalesTable form I added a command button as below:

pastedimage1596725816309v2.png

Then I make a simple On_Click event

pastedimage1596725903780v3.png

My question is, how to add a event handler to handle this on click event? The example I found uses OnValidatedWriteHandler, but mine is a button, which call a method.

Thank you in advance,

TN

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi ThienNgo,

    But you already added an event handler to handle OnClicked event. Each time when you click on button  SendRoadnet it will be executed.

    Or do you mean something else?

  • ThienNgo Profile Picture
    40 on at

    I have not added event handler in C# library. I only defined the OnClicked event.

    Because I don't add event handler in C# library, it throws me an error like this:

    pastedimage1596726948303v1.png

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi ThienNgo,

    It throws an error because you have issues in .net library code itself. I suspect that you have issue with private static Trasportation... variable initialization. Have you tried to comment it out, rebuild library and run again?

    Or do you know why type is TransportationWebService, but you instantate object of TransportationWebServiceClient?

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    As Sergei wrote, it has nothing to do with your event handler. You can run similar code from a runnable class and your C# code would fail the same way. Or, you can run only the C# code and it will fail the same way.

    You don't need to add any event handlers in your C# code. The event handler is in x++. it reacts to event in x++ and calls your C# code. The x++ part seems to work ok. You need to debug the C# code to understand what causes the exception.

  • Verified answer
    Joris dG Profile Picture
    17,775 on at

    If you read your error, it complains about your .NET class "type initialization" failing. You can read about type initialization. But from your screenshot, it's like your "private static TransportationWebService = ....". This is executed when your C# type (ReadNetMethods) is being loaded by .NET.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans