Error Handling fails: IF NOT CODEUNIT.RUN() THEN...

eYeeYe Member Posts: 168
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);
Kind Regards,
Ewald Venter

Answers

  • lvanvugtlvanvugt Member Posts: 774
    edited 2012-12-03
    Hi David,

    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.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • eYeeYe Member Posts: 168
    Strange... :-k

    Thank you very much for the reply. Will have to find some kind of workaround.

    Kind Regards,

    Ewald
    Kind Regards,
    Ewald Venter
  • pdjpdj Member Posts: 643
    The reason is the Bulk Insert buffer. The records are not inserted until the implicit COMMIT is fired when the codeunit it completed. The reason it works for the Customer table, is that the Bulk Insert buffer is disabled for tables with BLOB fields.
    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.
    Regards
    Peter
Sign In or Register to comment.