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

eYe
Member Posts: 169
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?
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
Ewald Venter
0
Answers
-
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.0 -
Strange... :-k
Thank you very much for the reply. Will have to find some kind of workaround.
Kind Regards,
EwaldKind Regards,
Ewald Venter0 -
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
Peter0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions