GetLastErrorText appears to be returning text different from the last thrown error under some circumstances for one of our clients running BC 18.8 On Premises. We have the following code for a document:
... Rec.SuspendStatusCheck(true); Rec."Count Process Retries" = 1; Rec."Last Error" := ''; Rec.Modify(); recInterfaceEntry."Last Error" := ''; recInterfaceEntry.Modify(); Commit(); ClearLastError(); if not Codeunit.Run(recInterfaceSetup."Inbound Transfer Codeunit", recInterfaceEntry) then begin str := CopyStr(GetLastErrorText(), 1, MaxStrLen(str)); recInterfaceEntry.Get(Rec."Interface Entry No."); recInterfaceEntry.WriteLog(str, recInterfaceEntry."Last Status"::TransferError); recInterfaceEntry."Last Error" := str; recInterfaceEntry.Modify(); ...
The executed codeunit starts a posting process, during which an error such as "Nothing to post" will occur. The error text is immediately copied to the variable str, and then logs them in a protocol table. The other day, our client logged multiple entries with an empty text. After some research, we could determine the error that caused the logs to be due to an invalid posting date, but this has been logged correctly in the past. When debugging on a test server, I noticed that breaks between the error and the GetLastErrorText causes the returned error message to be different. The origin of that error is unknown since the debugger doesn't break for any error except the one I'm expecting, and the message itself contains the name of a field that never appears in the project of our extension. Given that the actual server was never debugged, some other factor must have been at play, but I suspect these two incidents are related.
First of all, does GetLastErrorText return errors from only one session, or can it not delineate the origin of the error? Microsoft's official documentation of the GetLastErrorText-command confirms neither statement.
Second, could there be a different reason as to why GetLastErrorText would suddenly return an empty string? There are no other sections in our extension that add anything else with this Enum value as parameter, so it had to have come from the command.
hi
If you call the Codeunit.Run method to run a codeunit and an error occurs in the codeunit, then the error is displayed. However, if you also use the return value of the Codeunit.Run method, then the error is not displayed. In this case, you can use the GetLastErrorText method to determine whether an error has occurred and to see the text of the last error message that was generated. This example shows how to use the GetLastErrorText method. This example requires that you create two codeunits. Codeunit 50001 generates an error. Codeunit 50002 runs codeunit 50001 and if an error occurs, then it displays the text of the error.
DAniele
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156