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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Class name which cause the event or Table operation name

(0) ShareShare
ReportReport
Posted on by

Hi!

I have the same class method to operate all events which interesting me and in the event i have divided segments that maintain INSERT, UPDATE, DELETE..

How can i check which class name or which Table operation cause the event ??

The information which is needed for me is: INSERT, UPDATE, DELETE

Thank you in advance

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,840 Most Valuable Professional on at

    I'm not sure what you mean by "The information which is needed for me is: INSERT, UPDATE, DELETE", so I'll ignore it for now and focus on "how you can check which class name or which Table operation cause the event".

    Are you raising the event through a delegate, or you talking about handles attached to methods?

    In the first case, the usual approach is passing the object as the first parameter (typically called "sender").

    In the latter case, you'll get XppPrePostArgs object and you can call its getThis() method.

  • Community Member Profile Picture
    on at

    "The information which is needed for me is: INSERT, UPDATE, DELETE" i meant that i want to know which operation cause event...

    I use the second approach with handlers attached to methods but .getThis() return me instance witch record or sets of records... but i need to know what operation cause the event...

    Example...

    I have class EventHandler with method PostEventHandler... and i have this method attached as event for methods update(), insert(), delete() in two tables CustTable, InventTable.

    On event i can check which table it concerns by getThis().TableId

    But i need to know type of operation (INSERT, UPDATE, DELETE) or class name which caused event (insert(), update(), delete())

  • Verified answer
    Martin Dráb Profile Picture
    239,840 Most Valuable Professional on at

    So you don't want a "class name", you want the name of the method to which you attached the handler, right?

    I don't think that your implementation is suitable for your intent. I suggest you create three separate handers and if you want, you can easily call your current postEventHandler() method from there to handle the common logic. You obviously can use a parameter for the method, such as an enum with three elements (Insert, Update, Delete), which you would set appropriately from your three handlers.

  • Community Member Profile Picture
    on at

    I want the class name to which i attached handler :) Or the operation which is made on get.This() :)

    I want to have only one class for all three possibilities (INSERT, UPDATE, DELETE) because i dont want to have the same sourcecode in three classes... The event class insert record to another TABLE (MessagesQueue) and only diffrences between this classes will be value of one field of record... In my opinion creating 3 classes with almost the same code is not rigth.

  • Martin Dráb Profile Picture
    239,840 Most Valuable Professional on at

    All right, I already answered how to get the sender object. Then you can use is and as operators to work with it. You an also use classIdGet() and classId2name() to get the name, but object-oriented programming offers better ways.

    I never said anything about copying the same code. Put the common code to a single method and call it from handlers. If the only difference between your three classes is the value of one field, I think you have two more classes than you need.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 10

#2
Harisgillani Profile Picture

Harisgillani 4

#2
dserp Profile Picture

dserp 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans