Navision Timer 1.0

Navision Timer 1.0 Hello I read in the following topic about being able to catch the navision erros using The timer automation with the event TimerError. Here is my code. TempCU suppose to basically just errors out every time. Code: IF ISCLEAR(MyTimer) THEN CREATE(MyTimer); MyTimer.Interval := 1000; MyTimer.Enabled := TRUE; MyTimer::Timer(Milliseconds : Integer) if TempCU.RUN then; MyTimer::TimerError(ErrorString : Text[1024]) MESSAGE(ErrorString); What I expect from this is that TimerError Event would tigger and message would show me the ErrorString. Unfortunately it doesn’t work. What am I doing wrong? Has anybody tried this?

Remove the - if - in this line if TempCU.RUN then;

Removing the if statement will cause the error to show and the event still isn’t being tirggered becuase the code exits out.

But because you are using the CU’s return value, Navision doesn’t actually fire the ‘error event’. The CU return value seems to have been put in there for that purpose. It has some rpetty cool ways to use in NAS, but it has some serious limitations.

I wish they change the if to return a string which would be the error otherwise it’ll return empty string if it was successufull. Or create a global system variable, LASTERROR. that would be set to last the error. just like the USERID.

When you declare a codeunit as a codeunit type variable, and it errors out from within an IF statement, it is still alive. The only thing it loses is the record variable that caused the error. You could keep a text variable (let’s call it ErrorMsg) with a message of where in the process you are, and retrieve that message if the codeunit returns false. So let’s say you have a codeunit with the following code: ErrorMsg := ‘error validating Item number’; MyRec.VALIDATE(“Item No.”,ItemNo); ErrorMsg := ‘error validating Unit of Measure’; MyRec.VALIDATE(“Unit of Measure”,UofM); You add a function to that codeunit called GetErrorMsg, that returns the value of ErrorMsg. Then, calling it from another object, you do this: IF NOT MyCodeunit.RUN THEN BEGIN MESSAGE(MyCodeunit.GetErrorMsg); END; If validating the unit of measure causes the error, then the MyRec variable will have been destroyed, but the ErrorMsg variable is still intact within the codeunit, and you can retrieve its value from it.

Daniel That is not a viable solution, because I’m posting shipments for Orders, and there is no practical way to do this. except modify every single line to update the ErrorMsg text string.

so do something like: ErrorMsg := ‘unspecified error while posting shipment’; CU80.RUN(SalesHeader); And from your calling code you do: IF NOT MyCodeunit.RUN THEN BEGIN MySalesOrder.“New Error Message Field” := MyCodeunit.GetErrorMsg; MySalesOrder.“New Error Boolean” := TRUE; MySalesOrder.MODIFY; END; That way, you can filter the sales orders on the boolean field, and try posting manually, and have the user read the message. For sure, if you have a long list of sales orders to post, the ones that don’t error out will post without problems. Either way, you have a (partially) automated process. The point I am trying to make is that if you want to be able to catch every error, you will have to program around every error and give some meaningful feedback. Otherwise, you will have to make due with a more generic description. It’s all about compromise. There is no error object to catch in Navision, so you have to use whatever else is avaliable.

Yeah that is the solution I have been using, but wanted to see if there is a better way. I hope they add something in future releases of navision. Has anybody heard anything about Navision 5? I know in Navision 4 SP1. They’ve added FINDFIRST,FINDLAST,FINDRECORDSET. functions.