Hi,
does anyone have anyidea how to catch an error, and get the error message in order to do something with it.
So far I got to the point, where I can check if an error occured, but without any idea how to get the message
what I do is:
somecodeUnit.Setparams(...) //to set some params for the Run function
result := somecodeUnit.RUN;
The result is true or false, depending wheater there wasn't or was an error. But how to get the message eg. "Sales Order could not be bla bla bla"
Comments
In your somecodeunit create a text 'texterror'. As you are validating the records
texterror := 'validating No. field';
validate("No.",'blaah');
function geterror() as text {
exit(texterror)
}
somecodeUnit.Setparams(...) //to set some params for the Run function
result := somecodeUnit.RUN;
if result = false then begin
message(somecodeUnit.geterror);
end;
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
www.mibuso.com
www.navision-girl.com
www.dynamicsuser.net
The only way to get any error information at all is to follow ara3n's advice. You have to know though that you have to declare the codeunit as a variable, and not call it by CODEUNIT.RUN(number). Also, the record variable that causes the error will be destroyed, so that's why you will have to store the field value before you validate.
RIS Plus, LLC