Got codeunit 50000. Call it from a form at the moment before enabling the entry on the Job Queue to process from NAS.
It calls itself in order catch the exception and update the ParamEntry record.
Report::50000 populates a test table with 10 records.
Second time the codeunit is run, it tries to populate the table with the same records thus causing a "the record already exists" error.
But instead of the system executing the code after
IF NOT CODEUNIT.RUN(CODEUNIT::"50000", Rec) THEN BEGIN, it just breaks and doesn't update the status field to Failed. If I put an ERROR('My error message') in Report:50000 it does catch and handle the error.
Any reason why "the record already exists" would cause the error handling to fail?
OnRun(VAR Rec : Record "Job Queue Entry")
--------------------------------------------
GetParamEntry();
IF "Parameter String" <> '' THEN BEGIN
"Parameter String" := '';
IF NOT CODEUNIT.RUN(CODEUNIT::"50000", Rec) THEN BEGIN
ParamEntry.Status := ParamEntry.Status::Failed;
ParamEntry.MODIFY;
COMMIT;
ERROR(GETLASTERRORTEXT);
END;
ParamEntry.Status := ParamEntry.Status::Completed;
ParamEntry.MODIFY;
END ELSE
Code();
Code()
--------------------------------------------
REPORT.RUN(REPORT::"50000", FALSE, FALSE);
Answers
This is an anomaly of CODEUNIT.RUN that I am busy addressing in my CODEUNIT.RUN series, which is not finished yet.
Bodo did report about it in one of his blog posts and has filed it on msconnect.
The funny thing is that with a record variable based on the customer table it appears to work just fine; like you would expect. See my CODEUNIT.RUN #2.
But with - so far I tested - any other record it fails . See Bodo's post and my CODEUNIT.RUN #3.
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
Thank you very much for the reply. Will have to find some kind of workaround.
Kind Regards,
Ewald
Ewald Venter
Check this link for more info: http://msdn.microsoft.com/en-us/library/dd355341.aspx
PS: The Bulk Insert has been improved a bit from NAV2009 to NAV2013, but I do not know if it changes anything for this example.
Peter