Announcements
No record found.
Hi,
Greetings!
I have created an event "PostHandlerFor" on a standard table's method. The method is called by multiple standard classes.
I want the code of the event to execute only if called by a particular class.
Is there a way to get the name of the caller?
Regards,
Abhinay
Hi Abhinay,
Event handlers have no caller, they are called by the framework before or after the actual method.
If you were in the original method, how would you know the caller? Is there a parameter to identify the caller in the original method?
If the caller can be identified by a parameter, then in your event handler you can access that parameter using:
_args.getArg(identifierStr(variableName))
Which table's method you are trying to write the post handler for ? What you can do is to create a new field on the table and assign some value to it before calling and then inside the table's method, identify the caller based on that value. Hope this makes sense.
Let me know if you have further queries.
As mentioned by others, you can't access the caller if the table method doesn't know it. The event handler can't know more than the method where you hooked it.
Perhaps you should hook your event handler in the caller class, not the table? Could you share more details about what you are trying to achieve? Thanks!
Hi Pedro,
Thank you for your suggestion!
I used xSession::xppCallStack() and from there I got the list of classes.
It required less customization/ changes to objects and got the job done.
Hi Babar,
Since it is a standard table I wanted to avoid modifying it as much as possible. Please refer to my earlier reply to Pedro for my approach.
Hi Nikolas,
Thank you for your suggestion.
The calling classes are many (and part of standard code) and I wanted to avoid it.
Please refer to my reply to Pedro's suggestion for my approach.
I strongly recommend looking for a different design.
If you base your business logic on implementation details such as the name of a class or a position in the call stack, any otherwise save refactoring might break your system. You also make tight dependency of the called code on its caller (in addition to the dependency in the other direction), making further obstructions to maintainability, testability and extensibility.
If no better solution is possible, I would use a thread-level variable describing the context. Although global data is not optimal, this - unlike your solution - allows an intent-revealing design which doesn't depend on particular names or call stack, there is no tight dependency to the caller and the content can be set as needed from anywhere, including unit test classes.
Hi Martin,
Thank you for your suggestion, I appreciate it!
I will look-into it and try to come up with a way.
Could you please help me with some links/ material to refer to?
I will update this thread as soon as I have something to add here.
You used the call stack to identify the caller, but as Martin said, it's a bad design.
In my opinion the best alternative is to identify all methods that calls the method you are trying to extend, which I believe you already know since you would need a switch/case to act upon the call stack information.
After you discover all possible callers you can write a post event handler for each one. You can have a static method to centralize the business logic and then you call it in all event handlers. You can have the static method and the event handlers in the same class for the sake of simplicity.
This is more work indeed, but you will thank yourself if you ever need to maintain this code.
Hi Abhinay ,
You can take a look at below link . Take a look at option 3
Option 3: Disposable context
Scenario
You need to pass extra information from your code to a pre/post handler somewhere downstream.
community.dynamics.com/.../extensible-x-method-signatures
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.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Giorgio Bonacorsi 617
André Arnaud de Cal... 461 Super User 2026 Season 1
Syed Haris Shah 298 Super User 2026 Season 1