Alright, maybe I am stretching the truth a little, but I do get frustrated when people discount the Dynamics Report Writer as a useful tool. [Edit] I am not biased at all.... honest.
I recently worked on a support case where the partner had spent a significant amount of time trying to get Report Writer to print a SOP Invoice the way they wanted. In the end they contacted support and I had to explain that what they were trying to do was not possible with Report Writer alone. But..... could be achieved with some Visual Basic for Applications (VBA) code applied to the report.
I know that the Report Writer has limitations compared to some other dedicated report writing tools, but many of those limitations can be worked around with the use of Report Writer Functions in calculated field or using VBA scripts.
The Situation
The customer was importing Sales Order Processing (SOP) invoice transactions from an external system, but wanted the invoices printed from Microsoft Dynamics GP. The transactions would include one "Pack" item which is made up of a number of "Line" items. This is pseudo "Kit" functionality without actually using the kit features in GP. The "Pack" Item would have an Item Description starting with the characters "(P) " and will have a zero valued Unit Price and Extended Price fields. The "Line" items would have an Item Description starting with the characters "(L) " and will have values for the Unit Price and Extended Price. There would never be more than one "Pack" Item on a single Invoice. There can also be additional standard items (not "Pack or "Line" items) added to the invoice. The customer is not using Multi-currency, so we can ignore the complexity that would be added by Multi-currency.
The request from the customer was to sum the "Line" Items for an Invoice and show this total on the "Pack" item. Also the "(P) " and "(L) " prefixes needed to be removed.
Here is an example of the report information without modification:
Item Number Item Description Quantity Unit Price Extended Price PACK001 (P) Pack Item Number 001 2 $0.00 $0.00 LINE001 (L) Line Item Number 001 2 $4.00 $8.00 LINE002 (L) Line Item Number 002 4 $1.00 $4.00 MISC001 Miscellaneous Item Number 001 1 $5.00 $5.00 MISC002 Miscellaneous Item Number 002 2 $3.00 $6.00
Here is an example how the information is desired on the report:
Item Number Item Description Quantity Unit Price Extended Price PACK001 Pack Item Number 001 2 $6.00 $12.00 LINE001 Line Item Number 001 2 $0.00 $0.00 LINE002 Line Item Number 002 4 $0.00 $0.00 MISC001 Miscellaneous Item Number 001 1 $5.00 $5.00 MISC002 Miscellaneous Item Number 002 2 $3.00 $6.00
The Problem
Conditionally summing a number of lines on the invoice does not sound that hard. You can use a calculated field with a User Defined function to call the RW_Left() function to grab the left hand four characters of the Item Description. You could then use a conditional calculated field to return the Extended Cost when the left hand characters are "(L) " otherwise return zero. Add this calculated field to the report layout and change the data type to SUM. A final calculated field can return this sum from the report when the left hand characters are "(P) " otherwise return zero. This all sounds like it is a feasible solution and this was the approach that the partner was working on.
Except for one problem..... It would not work. They were able to see the summed total when it was in a footer, but it always showed as $0.00 in the "Pack" item.
The problem they were seeing is easily understandable when you remember that the Dynamics Report Writer is a single pass report writer. In simple terms, it means that it moves through the data records once (top to bottom) printing the sections as it goes.
For our situation, this means that the total for the "Line" items would not be known until after all the "Line" items have already been printed. As the "Pack" item is the first line on the invoice the sum of the "Line" items calculated at that point will always be 0.00 as no "Line" items have been printed.
A solution that could work would be to have the "Pack" item listed after the "Line" items in the invoice. However, this would require changes to the integration and maybe even the originating system. It was also not acceptable to the customer as they wanted the "Pack" item displayed first.
The bottom line, was that the desired end result was just not possible using the Dynamics Report Writer alone.
The Solution
Working with the partner, we created a Visual Basic for Applications (VBA) solution to the problem that produced the exact desired end result.
The first part of the solution is to modify the report layout to allow us to work with VBA in the H2 Additional Header section:
Once the layout changes are completed, we can can expose the report and the required fields to VBA:
Now we can develop the script to handle the rest of the report modifications using VBA. The code is based on previous blog articles (links below) and uses some standard techniques which can be copied and pasted and re-used as desired. The code can be broken down into five sections:
The Code
Below is the actual code used for the modified report. The packages exported from Customisation Maintenance are also included as attachments to the bottom of this post.
Note: If Multi-currency support was required, we would have to adjust the query to either sum originating or functional amounts depending on the currency view being printed. We would also need to change the method used to return the currency fields to the report (as per the articles below).
More Information
The solution described in this article used techniques from the following articles:
I hope this helps demonstrate how VBA can be used to go beyond what is possible with Report Writer alone.
David
06-Dec-2010: See the follow up post: Dynamics Report Writer is the Best Report Writer in the World cont.
Excellent illustration of Report Writer, David. Somehow, it's been projected that RW is the most rigid and unhelpful tool, while only few know about it's advantages. Hopefully this post change that mindset.
Mark thinks I have lost my marbles.... oh well, I knew something was missing.
Posting from Mark Polino at DynamicAccounting.net
msdynamicsgp.blogspot.com/.../david-musgrave-has-lost-his-marbles.html
PLEASE READ BEFORE POSTING
Please only post comments relating to the topic of this page.
If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.