Handling Validation Errors on NAS

I am creating an automated process to populate and post Sales Invoice in NAS. I am using a code unit to loop through a staging table and copy/validate the values to the Sales Header and Line. The problem is that if the validation creates an error, the entire process fails. Is there any way to catch an error caused by a field validation so that I can handle the error and continue processing other records?

Hi Darren - I’ve normally handled this by wrapping the functionality to handle each staging table line in a codeunit. That way you can loop through the staging table records and pass each one into the “handler” codeunit (which creates documents for that line) wrapped in an “IF” to trap for any errors. If the process succeeds, the line status can be updated to indicate it was handled. If the process fails, the line can be updated to indicate failure and a user can then open your staging table form and run a function (that you provide) to submit the line to the codeunit WITHOUT the IF wrapper to see the actual problem. So, your code for handling staging table records would look something like: lrecStaging.SETRANGE(Status,Status::Unhandled); REPEAT IF CODEUNIT.RUN(CODEUNIT::“Staging Table Handler”,lrecStaging) THEN lrecStaging.Status := lrecStaging.Status::Handled ELSE lrecStaging.Status := lrecStaging.Status::Errored; lrecStaging.MODIFY; UNTIL NOT lrecStaging.FIND(’-’);

Thanks Rob! That will work perfectly.

Are you using a timer to trigger the posting in the codeunit run by NAS? If so, there are several timers available that I’m aware of: CP Timer, Commerce Gateway Timer, and Navision Timer. The Navision Timer has two event triggers: Timer and TimerError. The TimerError event fires whenever there is an error in the code running in the Timer event; in addition, the error message is passed as a parameter to this trigger. That way you don’t have to wrap the functionality into a codeunit - just run the code and let the error happen and handle it in the TimerError trigger.