How to capture errors in NAV?

chandrurecchandrurec Member Posts: 560
Hi All,

I am having one doubt . I am inserting some entries to Item. We know that Item No is code of 20 char and in case if I am inserting a item with more than 20 char then when I use GETLASTERRORTEXT function will it capture the error . I need to store the error when I am inserting the field in log table.

Since When it reads the lines

recitem.no = some text more than 20 char then nav will stop in this line so where can I place the function GETLASTERRORTEXT.

If anyone knows how to address this problem , kindly let me know.

Thanks in advance.

Regards,
chandru.

Comments

  • lvanvugtlvanvugt Member Posts: 774
    Hi Chandru,

    To be honest i haven't checked this by trying, but I have always taken GETLASTERRORTEXTbeing the latest error thrown based on C/AL code execution (so based on ERROR, TESTFIELD, FIELDERROR).
    In your case, where you would like to catch the error based on the entering of more chars than allowed, this error is a platform and as such not based on C/AL code. I do not think that GETLASTERRORTEXT will catch that.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • vaprogvaprog Member Posts: 1,141
    The only situation I am aware of, in which you can automatically log an error, is when you use Codeunit.RUN(Rec) (or CODEUNIT.RUN(No,Rec)) while consuming the return value of that function.
  • KishormKishorm Member Posts: 921
    Vaprog is correct. What you need to do is have the main code in a codeunit, then you need something like...

    IF NOT mycodeunit.RUN() THEN BEGIN
    Errorlog.init;
    Errorlog."Entry No." := nextentryno;
    Errorlog.text := GETLASTERRORTEXT;
    Errorlog.INSERT;
    END;
Sign In or Register to comment.