Identical twins that aren't - codeunits 228 and 229

rocatis
Member Posts: 163
I recently had to do some modifications to codeunits 228 ("Test Report-Print") and 229 ("Document-Print"), specifically to the way Invoice Discount was calculated. In doing so, I was surprised to find that the functionality of the two codeunits (which is essentially identical) has actually been implemented in distinctly different ways.
Take the PrintSalesOrder function in codeunit 229. It essentially does the following:
Calculates Invoice Discount
Prints report using REPORT.RUNMODAL
Sounds about right!
Codeunit 228 pretty much mirrors codeunit 229, except it deals with test reports instead of documents.
Take a look at the PrintSalesHeader function. It essentially does this:
Prints report using REPORT.RUN
Calculates Invoice Discount
A somewhat up-side-down way of doing things (and quite illogical to me). Still, it works because the calculation finishes before the report is actually executed by the user (if you replace RUN with RUNMODAL the calculation won't be done until the report has finished printing).
So what if you were to execute some (very) time consuming code between the two parts? Could you actually risk printing the report without calculating the invoice discount? The answer (again: weirdly) is no. Even though the report has been called using RUN and not RUNMODAL, it is not "released" to the user before the remaining code (i.e. the discount calculation) has been executed. This surprised me somewhat.
In conclusion, both codeunits do what they were designed to do. But I see no conceivable reason why you would ever structure your code the way it has been done in codeunit 228 - it's simply counter-intuitive.
Any thoughts?
Take the PrintSalesOrder function in codeunit 229. It essentially does the following:
Calculates Invoice Discount
Prints report using REPORT.RUNMODAL
Sounds about right!
Codeunit 228 pretty much mirrors codeunit 229, except it deals with test reports instead of documents.
Take a look at the PrintSalesHeader function. It essentially does this:
Prints report using REPORT.RUN
Calculates Invoice Discount
A somewhat up-side-down way of doing things (and quite illogical to me). Still, it works because the calculation finishes before the report is actually executed by the user (if you replace RUN with RUNMODAL the calculation won't be done until the report has finished printing).
So what if you were to execute some (very) time consuming code between the two parts? Could you actually risk printing the report without calculating the invoice discount? The answer (again: weirdly) is no. Even though the report has been called using RUN and not RUNMODAL, it is not "released" to the user before the remaining code (i.e. the discount calculation) has been executed. This surprised me somewhat.
In conclusion, both codeunits do what they were designed to do. But I see no conceivable reason why you would ever structure your code the way it has been done in codeunit 228 - it's simply counter-intuitive.
Any thoughts?
Brian Rocatis
Senior NAV Developer
Elbek & Vejrup
Senior NAV Developer
Elbek & Vejrup
0
Comments
-
rocatis wrote:So what if you were to execute some (very) time consuming code between the two parts? Could you actually risk printing the report without calculating the invoice discount? The answer (again: weirdly) is no. Even though the report has been called using RUN and not RUNMODAL, it is not "released" to the user before the remaining code (i.e. the discount calculation) has been executed. This surprised me somewhat.
Any thoughts?
I think why the report.run is executed after the discount calculation, is because the calculations locks the tables on which the report should run, so the report waits until the locks are released.
However, I do agree that this is an odd way of written code.0
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