The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
Gets the text that was included in the last error message that was generated.
String := GETLASTERRORTEXT
Property Value/Return Value
The text string that was contained in the last error message that was generated by Dynamics 365.
If no error has occurred, then the method returns an empty string.
If you call the GETLASTERRORTEXT method immediately after you call the CLEARLASTERROR method, then an empty string is returned.
The result of the GETLASTERRORCODE Methodis not translated into the local language. The result of the GETLASTERRORTEXT method is translated into the local language.
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.
// Codeunit 50001 // OnRun trigger ERROR(‘Some error message.’); // Codeunit 50002 // OnRun trigger CLEARLASTERROR(); IF NOT Codeunit.RUN(50001) THEN MESSAGE(‘The last error was: ’ + GETLASTERRORTEXT);
In this example, because the IF statement uses the return value of the Codeunit.RUN method, the error from codeunit 50001 is not displayed. Instead, you use the GETLASTERRORTEXT method to display the error.
When you run codeunit 50002, the message window displays the following:
The last error was: Some error message.