Suppose there is a subscription on the event OnAfterDelete "Sales Line"
It should only execute the subscriber code when it is not being called from codeunit 80.
How would that be possible?
Is the only method to do this using the this nice trick from Vjeko?
http://vjeko.com/detecting-current-object-type-and-id-using-some-funky-net-interop/
Answers
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
Archerpoint India Pvt. Ltd,Chennai.
@Kishorm : It would be possible, but yes I agree, it is not easy.
This is an example of the stacktrace:
Best guess would be to look through the stacktrace, and to check if there is a line with CodeUnit80 OnRun.
If I gather the stacktrace and show it in the Error Message it shows:
So yes, maybe I'll give it a try.
Code would be something like this:
...and then you could use it for other stuff if you needed to
You could also check the RunTrigger parameter first - so if this is TRUE then you know already that it's not being called from CU 80 and don't need to check the StackTrace
Remco, you need to rethink your business case.
|To-Increase|
@Sog That is a good option, but it would definitely have an impact on the performance.
1) ...do something different depending on whether the line is being deleted from the posting codeunit or not - not unreasonable (standard NAV does some stuff slightly differently in CU 80 depending on whether it's called from the Inventory Pick/Put-away or not)
2) ...try to achieve this by only having code in an event, I.e without making changes to standard NAV objects such as codeunit 80 - again not unreasonable (this is the way we are being to told to do things these days)
Yes, he has come up with a creative solution - but is this really a bad thing?
Until someone comes up with a better solution, I think what has been suggested is quite reasonable