I came across a situation where I needed to use CODEUNIT.Run(), but I
receive an error indicating I cannot use it in this situation. It mentions
something about not being able to use the return value from CODEUNIT.Run()
within a write transaction. However, I need to use the return value to do
what I am trying to achieve, so I feel somewhat stuck. The error also
mentions that I could move my code outside the write transaction, but that's
not feasible for a few other various reasons.
Let me explain exactly what I'm trying to do, to see if there are any other
options I am missing.
I am attempting to call into a COM DLL (Automation variable), but the call
can throw an exception if the URL is invalid. I want to catch this error,
but if I simply call this method directly, I get a message saying something
along the lines of "This message is for C/AL programmers. The call to xxx
failed ..." I discovered I could override this by placing the automation
method call into the OnRun method of a codeunit and call CODEUNIT.Run(),
using the return value to determine whether it failed or not. By doing that,
I could override that error message and display one that is slightly more
user friendly. However, as noted earlier, I cannot always do this. Is there
any way to override the error/exception returned by the automation call?
Any help is greatly appreciated.
Thanks,
Greg
"Greg" <Gr...@discussions.microsoft.com> wrote in message
news:ACA2B3A3-5CFA-4B15...@microsoft.com...
The only thing I fear about doing this is that it will commit things that
shouldn't be committed. The place where I am attempting to do this is nested
within some stock NAV code (in several places), and so I fear it would affect
the original NAV code in a harmful way. In particular, this code is called
during tax calculation, which is in turn called from OnAfterGetRecord() on
the Sales Order Stats. form, or when a document is released, or, most
importantly, when a document is posted. A COMMIT halfway through posting,
which is when we calculate tax, would likely be disasterous. Is there any
other workaround to this?
Thanks,
Greg
"Greg" <Gr...@discussions.microsoft.com> wrote in message
news:40908E9F-54E2-4EB4...@microsoft.com...
VB6 used to be very good for this; DotNET not so much, as there's going to
be a large performance impact especially if you're not calling it often.
Robert.