Hi ,
I am trying to create a function( OR CodeUnit) that will catch Error in NAV and dump it in a Error Log Table. We want to use NAS, that will Post a Receipt for a Purchase order. Suppose that there was an error while posting, this Error should be inserted to a Error Log Table BUT not commit anything before then.. i.e - any other insert on any other table should fail.
e.g.
Suppose that you had
Table1.Insert();
Table2.Insert();
Table 3.Insert();
IF something=’’ THEN
IF NOT TrapError THEN
ERROR(‘ Something is blank’)
ELSE
BEGIN
WriteError(‘Somethig is blank’);
EXIT()
END;
I want WriteError to write to an Error Log but want the insert on Table 1,2 and 3 to fail. I believe that a commit on the WriteError Function will also insert on T1,T2, and T3 which is not desired.. Any thoughts? Or automation out there? I.e I don’t want to use a TXT File.
0
Comments
It will call your codeunit in the following way.
Onrun
If not Codeunit.run() then begin
WriteLog(getlastErrortext);
clearlastErrorText;
commit;
end;
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I will NEVER go the way when you need to modify all calls of ERROR function etc. Because there are validate errors testfield errors etc. Ara3n's solution is much better, because it is generic and you do not need to modify existing code. It is working on NAV 5.0 and higher. If you are using older NAV, you can do technical upgrade or you can use another way, using NTimer automation which have OnError event to catch the error and write it. Than you only need to call the function for posting the document in OnTimer event for each document...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n