03.10.2012, 02:57 | #1 |
Участник
|
The goal with this post is to show how NOT to use Code.GetData and Code.SetData in the one of the most common used Document report in NAV, our beloved 206 report. Code.GetData and Code.SetData is used in the header to of the report to keep field values in sync with current sales order currently being printed in the body. Just adding the field in the header will not keep this synchronization, unfortunately. Yes we can now add fields directly into the header in RDLC 2008, used in NAV 2013. Actually when I realized that this was possible in RDLC 2008, I was actually crying, because this limitation in RDLC 2005, used NAV 2009, has been a huge pain, at least for me.
But in I this example which I’m about to show you, I will not use this new capability in RDLC 2008. This blog post is pretty long so I would like to show you the header in Report 206 before and after my changes. Looking at the before and after images should give you an idea what this post is all about. Here is a screenshot of the header in standard report 206 in just released NAV 2013: As you can see a lot of <<Expr>> all over and not really human readable, and it gets worse when opening one of these expression, because the values are just Code.GetData and a number. And here is a screenshot of the header after my changes which I explained in details in this post: As you can see now all fields are visible and if you need to make modification it easy to locate where your changes need to take place. So here we are, NAV 2013 have just been released and standard report 206 is still using Code.GetData and Code.SetData, just like it did in NAV 2009. And they way it is designed it needs to use Code.GetData and Code.SetData. I will show you how you simple can change this so the report becomes human readable, because i.e. “Code.GetData(54,1)” in my eyes is not. For the people not familiar with Code.GetData and Code.SetData in RDLC reports I will do a small introduction now. If you already know how this works you can skip this section and go directly to the “Redesigning report 206.”, where I show you how to get rid of Code.GetData and Code.SetData in report 206. Understanding Code.GetData and Code.SetData To understand how Code.GetData and Code.SetData works there are 4 areas we need to look at. As I always I like to visualize things so if we look at the header and the top of the body of report 206 it looks like the below picture:
So as I said in the beginning my goal was to not use Code.GetData and Code.SetData in report 206, and when you think about it, using Code.GetData and Code.SetData is a complete workaround and not something the SSRS Team thinks much about, so there is no guarantee this will work in future version. So I urge the NAV team to work closely with the SSRS to work out a solution for this, so we in a future release can have document reports with out Code.GetData and Code.SetData. Unless of course the NAV team come up with yet another report tool for document reports in the future! OK enough about Code.GetData and CodeSetData. Now let’s us simplify the report and get rid of all this unnecessary transferring of fields from body to header. Redesigning report 206 I want to have each field visible in the report, so when another developer opens the report, he is not clueless of what all these <<Expr>> and Code.Get(x,x) means. So in all it’s simplicity I’m just going to add more header lines to the main table of the report which is in the List control in Body of the report. I know this will work because we already have all the fields stored in the hidden table used for Code.GetData and Code.SetData. This works because the List Control is Grouped by the [No_SalesInvHdr], which is the Sales Invoice Header No. Then I will move all the 54 fields in header lines to the body and remove them from header. First thing I do is to measure the size of all the fields in the header. These is around 10cm in height. So to make room to all the fields which is now going to body I need to make room for them by adding 10 cm to each element in the overall List Control. To easily get an overview of which elements that I have in my report, always use “Document Outline”: Document Outline can be found in “View / Other Windows / Document Outline” or simply by hitting CTRL+ALT+T. In the List control the first thing is always a Rectangle and in my rectangle I can see that I have a textbox(Used for counting pages) 4 tables and another list control. So in “Document Outline” I simply select from the bottom, in this case the “list2” control. With the “list2” control selected I navigate to the Location property in the “Properties” and then increase the “Top” value with 10cm Before: After: I repeat this for all the elements except for the “NewPage” textbox which I would like to be at the top, because I have seen this not working when not in the top of the list. So just be sure. The I will then add new header lines to the main table in the report, in this case I’m adding 22 new header lines. Then when the 22 new headers lines have been added I will add new columns and decrease others so I can locate the fields just like they where placed in the header. This is a bit cumbersome, but I use Excel to my calculations, then I’m sure that I leave other columns intact with same values. When you get good at this it only takes a few minutes to add new columns in a existing table. Now the table headers are ready, so I start going by each of the fields in the header resolve the Code.GetData values to actual fields. This takes a bit of time. When this is completed I’m pretty much done, but before I can delete the small hidden table with all fields in Body and Code.SetData text box in header, I need to make a small Page caption label because Page number can only live in Headers or Footer of a report. Notice that the label I have created becomes a parameter to the report and is not repeated in each row of the dataset. This is new thing in NAV 2013, but I dig deeper into this subject in a future post. So with my PageCaption no longer using Code.Get, I can delete the small table which contains all fields in one textbox and delete the Code.SetData textbox in header. Now I have 3 Images shown in report header and the Page No. The 3 images don’t work, no matter if I select Left, Center or Right in Sales & Receivables setup Company Logo is printed to the left, so this seem not to have been tested in NAV 2013. But no matter what, I don’t like the idea of having the image repeated in the dataset, just does not make sense, especially from a performance point of view. Here is a small snapshot of the dataset with the logo repeated in standard report 206. Imagine what a 1 MB large company logo does to your dataset, when printing multiple Invoices with many sales lines!!! So when designing report 206 I always delete the Images in header, mainly for performance reasons, but also because I have not seen customer yet who required the possibility to change the positions of their Company logo on Document reports. This is something which is fixed, and maybe only change when they change logo. With the 3 images gone I add a new image, but instead of using from database, I embed the company logo to the report, because then I’m sure that the image is only sent once to Report Viewer. I took the liberty to change the logo to Abakion which is the best NAV partner in Denmark You can find the modified report 206 from the W1 version here in, txt, fob and a print in PDF from the demo database in NAV 2013. Thanks, Claus Lundstrøm, Abakion.com Читать дальше
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
04.10.2012, 23:05 | #2 |
Участник
|
Офигенная автоматизация.. Ради чего только ?
|
|