MICROSOFT DYNAMICS® NAV 2009
REPORT DESIGN
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of ...
35 downloads
1042 Views
9MB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
MICROSOFT DYNAMICS® NAV 2009
REPORT DESIGN
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Last Revision: June 2009 The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.
© 2009 Microsoft Corporation. All rights reserved. Microsoft Dynamics®, Microsoft® PowerPoint® Microsoft® SQL Server® and Microsoft Dynamics® NAV MorphX® are trademarks or registered trademarks of Microsoft Corporation. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. This course content is designed for Microsoft Dynamics® NAV 2009.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Table of Contents Introduction
0-1
Welcome ............................................................................................................ 0-1 Microsoft Dynamics Courseware Contents ........................................................ 0-2 Documentation Conventions .............................................................................. 0-3 Student Objectives ............................................................................................. 0-4
Chapter 1: Creating Reports
1-1
Objectives ........................................................................................................... 1-1 Introduction ......................................................................................................... 1-1 Anatomy of Reports ............................................................................................ 1-4 Creating and Transforming the Layout ............................................................. 1-14 Report Properties ............................................................................................. 1-27 Building the Request Form/Page ..................................................................... 1-32 RoleTailored Client-Only Reports ..................................................................... 1-41 Summary .......................................................................................................... 1-42
Chapter 2: Interactive Features
2-1
Objectives ........................................................................................................... 2-1 Introduction ......................................................................................................... 2-1 Working with Headers and Footers .................................................................... 2-2 Print Preview and Print Layout ......................................................................... 2-21 Working with Visibility Options.......................................................................... 2-22 Interactive Sorting ............................................................................................ 2-26 Working with Document Maps .......................................................................... 2-30 Summary .......................................................................................................... 2-49
Chapter 3: Adding Code to a Report
3-1
Objectives ........................................................................................................... 3-1 Introduction ......................................................................................................... 3-1 Using Variables and C/AL Code in a Report ...................................................... 3-2 Working with Report Expressions....................................................................... 3-5 Understanding and Using Simple and Complex Expressions .......................... 3-13 Expression Examples ....................................................................................... 3-16 Anatomy of the Sales Invoice Report ............................................................... 3-27 Summary .......................................................................................................... 3-40 Lab 3.1a - Adding Conditional Formatting to a Report - I ................................. 3-43 Lab 3.1b - Adding Conditional Formatting to a Report - II ................................ 3-47 Lab 3.2 - Using Custom Code in the Visual Studio Report Designer ............... 3-54
Chapter 4: Design Considerations
4-1
Objectives ........................................................................................................... 4-1 Introduction ......................................................................................................... 4-1 Report Patterns and Recipes ............................................................................. 4-2 Report Rendering Considerations .................................................................... 4-15 Useful Tips ....................................................................................................... 4-18 Summary .......................................................................................................... 4-25 Lab 4.1 - Creating Green Bar Reports.............................................................. 4-27 Lab 4.2 - Creating a Top X Report ................................................................... 4-30
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
i
Report Design in Microsoft Dynamics® NAV 2009 Chapter 5: Running Reports
5-1
Objectives ........................................................................................................... 5-1 Introduction ......................................................................................................... 5-1 The ReportViewer Control .................................................................................. 5-2 Print a Report from the RoleTailored Client........................................................ 5-4 Hyperlinks to Reports ....................................................................................... 5-11 Hyperlinks in E-mails ........................................................................................ 5-19 Hyperlinks in a Report ...................................................................................... 5-20 Interesting Links ............................................................................................... 5-24 Lab 5.1 - Add a Report to the RoleTailored Client............................................ 5-29 Lab 5.2 - Call a Report from a Web Service ..................................................... 5-33 Summary .......................................................................................................... 5-49
Chapter 6: Appendix
6-1
Objectives ........................................................................................................... 6-1 Introduction ......................................................................................................... 6-1 Understanding Form Transformation.................................................................. 6-2 Preparing Form Transformation ....................................................................... 6-13 Transforming Forms ......................................................................................... 6-19 Summary .......................................................................................................... 6-28
ii
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Introduction
INTRODUCTION Welcome We know training is a vital component of retaining the value of your Microsoft Dynamics® NAV 2009 investment. Our quality training from industry experts keeps you up-to-date on your solution and helps you develop the skills necessary for fully maximizing the value of your solution. Whether you choose Online Training, Classroom Training, or Training Materials; there is a type of training to meet everyone's needs. Choose the training type that best suits you so you can stay ahead of the competition.
Online Training Online Training delivers convenient, in-depth training to you in the comfort of your own home or office. Online training provides immediate access to training 24 hours-a-day. It is perfect for the customer who does not have the time or budget to travel. Our newest online training option, eCourses, combine the efficiency of online training with the in-depth product coverage of classroom training, with at least two weeks to complete each course.
Classroom Training Classroom Training provides serious, in-depth learning through hands-on interaction. From demonstrations to presentations to classroom activities, you receive hands-on experience with instruction from our certified staff of experts. Regularly scheduled throughout North America, you can be sure you will find a class convenient for you.
Training Materials Training Materials enable you to learn at your own pace, on your own time with information-packed training manuals. Our wide variety of training manuals feature an abundance of tips, tricks, and insights you can refer to again and again:
Microsoft Dynamics Courseware The Microsoft Dynamics Courseware consists of detailed training manuals, designed from a training perspective. These manuals include advanced topics as well as training objectives, exercises, interactions and quizzes. Look for a complete list of manuals available for purchase on the Microsoft Dynamics website: www.microsoft.com/Dynamics.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
0-1
Report Design in Microsoft Dynamics® NAV 2009
Microsoft Dynamics Courseware Contents Test Your Skills Within the Microsoft Dynamics Training Materials you find a variety of different exercises. These exercises are offered in three levels to accommodate the variety of knowledge and expertise of each student. We suggest you try the level three exercises first, if you need help completing the task look to the information in the level two exercises. If you need further assistance each step of the task is outlined in the level one exercise.
Challenge Yourself! Level 3 exercises are the most challenging. These exercises are designed for the experienced student who requires little instruction to complete the required task.
Need a Little Help? Level 2 exercises are designed to challenge students, while providing some assistance. These exercises do not provide step by step instructions, however, do provide you with helpful hints and more information to complete the exercise.
Step by Step Level 1 exercises are geared towards new users who require detailed instructions and explanations to complete the exercise. Level 1 exercises guide you through the task, step by step, including navigation.
Quick Interaction: Lessons Learned At the end of each chapter within the Microsoft Dynamics Training Material, you find a Quick Interaction: Lessons Learned page. This interaction is designed to provide the student with a moment to reflect on the material they have learned. By outlining three key points from the chapter, the student is maximizing knowledge retention, and providing themselves with an excellent resource for reviewing key points after class.
0-2
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Introduction
Documentation Conventions The following conventions and icons are used throughout this documentation to help you quickly and effectively navigate through the information. CAUTION: Cautions are found throughout the training manual and are preceded by the word CAUTION in bold. Cautions are used to remind you of a specific result of a specific action which may be undesirable. HINT: Hints are found throughout the training manual and are preceded by the word HINT in bold. Hints are used to suggest time-saving features or alternative methods for accomplishing a specific task. NOTE: Notes are found throughout the training manual and are preceded by the word NOTE in bold. Notes are used to provide information which, while not critical, may be valuable to an end user. BEYOND THE BASICS: Advanced information found throughout the training manual is preceded by the words BEYOND THE BASICS in bold. Beyond the Basics provides additional detail, outside of standard functionality, that may help you to more optimally use the application. EXAMPLE: Examples are found throughout the training manual and are preceded by the word EXAMPLE in bold. Examples bring to light business scenarios that may better explain how an application can be used to address a business problem.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
0-3
Report Design in Microsoft Dynamics® NAV 2009
Student Objectives What do you hope to learn by participating in this course? List three main objectives below. 1.
2.
3.
0-4
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports
CHAPTER 1: CREATING REPORTS Objectives The objectives are: •
Describe the roles of reports and know the anatomy of a report in the Classic client and in the Role Tailored client.
•
Understand the way a report layout is designed and executed in the Classic client and in the RoleTailored client.
•
Know how frequently used report properties from the Classic reports are implemented in RDLC report layouts.
•
Know what the request options form in a Classic report is used for and how to build a request options page for the RDLC report layout.
•
Know what happens when a Classic report is run on the RoleTailored client and what the requirements are to do this.
Introduction Microsoft Dynamics® NAV 2009 is one of the most innovative releases in the product’s history. This chapter describes the main differences between Microsoft Dynamics NAV 2009 and all previous versions. It also describes the competitive advantages of the Microsoft Dynamics NAV 2009 release.
Microsoft Dynamics NAV 5.0 Microsoft Dynamics NAV 5.0 is a two-tier client-server solution application. Two-tier architecture models are used in the true Client/Server Distributed Data solution. In two-tier architectures, the data and data manipulation layers typically reside on the server tier, whereas the application logic, presentation logic, and presentation layers are handled by the client tier.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-1
Report Design in Microsoft Dynamics® NAV 2009 The architecture of Microsoft Dynamics NAV 5.0 consists of a Database Management System (DBMS) that resides on the server and a Graphical User Interface (GUI) that resides on the client.
FIGURE 1.1 THE MICROSOFT DYNAMICS NAV 5.0 ARCHITECTURE
Microsoft Dynamics NAV 2009 Unlike previous versions, Microsoft Dynamics NAV 2009 is built on a three-tier architecture model. Microsoft Dynamics NAV 2009 is the first release to introduce a new layer in the traditional two-tier architecture. This additional layer, which is often referred to as the “service tier,” is designed to host and execute all the business logic. The service tier acts as a middle tier between the server and the client tiers.
1-2
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports The introduction of the three-tier architecture however does not mean the end of the two-tier architecture. In Microsoft Dynamics NAV 2009, the three-tier and two-tier architectures coexist: while the RoleTailored client interacts with the RoleTailored components, the Classic client works in the traditional way. Additionally, the Classic client remains an essential component for developing and administering Microsoft Dynamics NAV applications. (For example, you must use the Classic client to upload your Microsoft Dynamics NAV 2009 license file or to create reports and pages that will be used on the RoleTailored client. More information on the architecture can be found in the Microsoft Official Curriculum (MOC) 80040, Installation and Configuration in Microsoft Dynamics NAV 2009. Although the two-tier architecture has proven its value through the years, the three-tier architecture offers many competitive advantages.
Openness There is not much openness in the Microsoft Dynamics 5.0 system. While C/SIDE allowed integration with external applications to automate specific tasks (using Automation), it is very difficult for external applications to access the data and especially the business logic of Microsoft Dynamics NAV 2009. C/FRONT and ODBC allowed access to the data, but the business logic is out of reach. The new architecture allows objects (pages and codeunits) to be exposed as Web services. This means that the object (and its business logic) is made available as a .NET assembly and can be called from any external application speaking SOAP (Single Object Access Protocol).
Multiple Clients This technological innovation had another impact. By making the business logic available on a separate tier and as a .NET assembly, Microsoft opened the gates for client applications other than the Classic client. Microsoft Dynamics NAV 2009 is the first release to support multiple clients. It is now possible to develop applications on multiple software (WinForms, Web applications) or hardware platforms (computer, mobile devices, and so on). Currently, the RoleTailored client is the first implementation, but soon other clients are expected to follow, such as a SharePoint client.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-3
Report Design in Microsoft Dynamics® NAV 2009 Enhanced Productivity through the RoleTailored Interface The interface of the RoleTailored client is roletailored, which means it is built around the way users work and the tasks they execute in their daily job. The Classic client does not distinguish between the different types of users in a company; it offers all available functionalities. As a result, some forms in Microsoft Dynamics NAV 5.0 are overloaded with functions and buttons rarely used, while other relevant information remains hidden from the user. In the RoleTailored client, the interface is optimized for employees to fulfill their jobs. It offers functions that are relevant for a specific task. Instead of having to search for a specific function in the menus, users have instant access to all the relevant features they need, which results in higher productivity. Although the new architecture made the product more open, it also implied certain challenges. Since the business logic is no longer executed on the client, some of the functionalities required (major) design changes. In addition, the new solutions needed to support multiple display targets in an easy way. Two areas were severely impacted by this architecture: data presentation and reporting. Microsoft has solved these challenges by introducing pages and by further integrating with other Microsoft products, like Microsoft Visual Studio® and Microsoft SQL Server® Reporting Services. Pages are the RoleTailored client equivalent for the Classic form object. Unlike classic forms, pages have no fixed width and height, but resize automatically in the function of the display target. The new reporting solution in Microsoft Dynamics NAV 2009 is taking advantage of the enhanced functionalities of SQL Server Reporting Services. This course describes the new reporting solution.
Anatomy of Reports This lesson describes the roles and components of reports in Microsoft Dynamics NAV 2009. It describes some general concepts related to report objects. Reports print information from a database and they can structure and summarize information. Reports are used to print documents such as invoices and to process data without printing anything. Creating reports includes designing both the business logic that covers the kind of information the report will contain, and the layout that deals with how the report will look when it is printed. In addition, developing reports for the RoleTailored client requires additional design consideration. In Microsoft Dynamics NAV, reports have several purposes: •
1-4
Print information from a database in a structured way. Typical examples are the Customer - List and the Customer - Order Detail (reports 101 and 108).
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports •
Print a company's official documents. For example, report 206, Sales - Invoice prints an invoice together with its relevant information.
•
Automate recurring tasks, such as updating all prices in the item list. This can be performed by using C/AL code in a codeunit, but to use a processing-only report makes it much easier because of the powerful data modeling available for report design. For example, report 794, Adjust Item Costs/Prices.
A report consists of a report description. The report description specifies how data is collected (the logical design or the dataset) and presented on screen or on paper (the visual design or layout). The report description includes both the logical and the visual design and is not directly visible to the user. In Microsoft Dynamics NAV 5.0 the report description contains properties, triggers, sections, controls and a request form. In Microsoft Dynamics NAV 2009, two more components are added which are required for reports developed for the RoleTailored client: a request page and RDLC data. The following figure shows components of a report and how they are related:
FIGURE 1.2 THE REPORT DESCRIPTION
Data Items The data model of a report is built from data items. A data item corresponds to a table. When the report is run, each data item is iterated for all records in the underlying table. When a report is based on more than one table, you can establish a hierarchy of data items to control how the information is processed.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-5
Report Design in Microsoft Dynamics® NAV 2009 Creating a hierarchy can be done by linking and indenting the data items. Data items with the same level of indentation are processed sequentially.
Properties The report description contains properties that are related to the report itself and properties that are related to the other components of the report (data items, sections, request form or request page and controls). When designing reports for the RoleTailored client in Visual Studio, you can also define a number of properties. These properties are saved in the RDLC data.
Triggers Triggers represent predefined events that occur during report execution and that cause the system to execute specific user-definable C/AL statements. Triggers in a report can be divided into seven categories: •
Report triggers
•
Data item triggers
•
Section triggers
•
Request form triggers
•
Request page triggers
•
Request form control triggers
•
Request page control triggers
Sections Reports in Microsoft Dynamics NAV can be printing or nonprinting reports. A nonprinting report is used for processing a certain task and does not produce a displayed output. A printing report displays the result in the screen or prints output on the paper. This display is controlled by the visual design of the reports. In Microsoft Dynamics NAV 2009, there are two different visual designs: •
Classic report layout which is defined in report sections.
•
Client report definition which is the RDLC data.
A section is a visual element of a report. It can be thought of as a block of information to print on paper. In a printing report, each data item can have one or more sections. The report itself can be composed of several sections. The number of times a section is printed depends on the section type.
1-6
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports The visual element of a report includes the sections. In a printing report, one or more sections can be attached to each data item. There are several types of sections. Each has a specific function. Usually, the bulk of the data is printed in the Body section of a data item, whereas the Header section of the data item is used to print information before any record of the data item is printed, such as column captions. There can be reports where the Body section is not used at all, and all information is printed in other sections.
Summary In Microsoft Dynamics NAV 2009, it is still possible to design and run reports for the Classic client, and to design reports in the Visual Studio Report Designer. However, the new architecture and the new client allow making use of other products and features to design reports.
The Section Designer The Section Designer is a special part of the Report Designer where you can build the visual layout of the report. To open the Section Designer, select View, Sections in the Report Designer. (When you are in the C/AL Editor of a report, the menu item is not enabled.) In the Section Designer, you can view all sections that are defined in the report. If a report is created using a wizard, the wizard will add the necessary sections for you. If starting from a blank report, all that can be viewed is a Body section for each data item in the report. Body sections are used to print the details of the records in the table. Sections are represented by a horizontal grey bar, which display the type of section and the data item it is linked to. Each section is linked to a data item. In each section, you can use the Field Menu to get access to the fields in the underlying table. 1. To add one or more fields to a particular section, select the field(s) in the Field Menu and click the Body section. The fields and corresponding captions will be added to the section. 2. Now reposition or resize the controls to fit the layout needed by using the mouse, or by using the Properties of the control. To open the Properties window, select the control, then select View, Properties or press Shift+F4. If you choose not to use the field menu, or to display the value of a variable in a section, controls can be added manually, and they can be linked to a specific field or variable by specifying the SourceExpr property. Remember that some controls (such as textbox, checkbox, radio button, and picture) are data controls and must be tied to a variable or field. Other controls (like shape, image, and label,) do not require a SourceExpr.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-7
Report Design in Microsoft Dynamics® NAV 2009 In the Section Designer you can add as many sections as needed for any data item. To do this, select View, Insert and select the type of section to add, and the data item to which the new section applies. If more sections of the same type are being added to a report, select the position of the new section (before or after the current section). The layout defined in the Section Designer is a What You See Is What You Get (WYSIWYG) layout: the size of each control and section in design time is identical in runtime. For processing-only reports, no sections can be defined. Remember that setting the report property ProcessingOnly to Yes causes all sections to be deleted. Moreover, the RDLC data is removed from the object. A warning message displays to inform the user about the deletion.
Section Types The following section types can be added:
1-8
Section Type
Description
Supported in RoleTailored Client
Header
This section prints first for a data item. By default, it only prints one time every time that the data item is processed. However, it can be set to print on every page.
Yes
GroupHeader
This section prints immediately before the first record in a group that is processed. This section only prints if the GroupTotalFields property for the data item is set, and the data item is appropriately sorted.
No
TransHeader
This section prints at the top of a page for a data item that is continued from the previous page.
No
Body
This section prints one time for every record that is processed by the data item. If a record is skipped or filtered out, this section does not print for that record.
Yes
TransFooter
This section prints at the bottom of a page for a data item that is continued on the next page.
No
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports Section Type
Description
Supported in RoleTailored Client
GroupFooter
This section prints immediately after the last record in a group that is processed. This section only prints if the GroupTotalFields property for the data item is set, and the data item is appropriately sorted.
No
Footer
This section prints last for a data item. By default it only prints one time every time that the data item is processed, but it can be set to print on every page. This section can be specified to be printed at the bottom of the page.
Yes
Each section can be added several times, even for the same data item. Not all section types from the Classic client are available in the Visual Studio Report Designer. In addition, section triggers like OnPreSection and OnPostSection are not supported in the Visual Studio Report Designer.
The Structure of Reports in Visual Studio Not only does the new architecture make Microsoft Dynamics NAV 2009 more open, robust and scalable, it also allows further integration with other external applications, and to enhance some of the existing functionalities. On the other hand, the new RoleTailored client also raises a number of challenges: •
All features that are available in the Classic client are available for the new RoleTailored client (and for other clients)
•
The differences with Microsoft Dynamics NAV 5.0 are kept to a minimum, to guarantee backward compatibility and maintainability. The goal is to serve multiple clients with one and the same object - if possible.
•
The new solution needs to be usable on multiple display targets (clients).
All these requirements are met in the new reporting solution of Microsoft Dynamics NAV 2009. The starting point for designing RDLC report layouts is still the Object Designer.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-9
Report Design in Microsoft Dynamics® NAV 2009 Reports run in Microsoft Dynamics NAV 2009 – both the classic and the new client – are still designed in the existing classic report designer. However, the RDLC report layout is built in Visual Studio. Visual Studio Report Designer offers several new options and features. Furthermore, due to its thorough integration with Microsoft SQL Server, it is possible to take advantage of the reporting capabilities of Microsoft SQL Server Reporting Services, including: •
Richer Formatting
•
Interactive Sorting
•
Graphics and Charts
•
Additional Standard Export Possibilities (PDF, Microsoft® Office Excel®)
The new environment in Visual Studio (VS) report designer relies completely on the data structure you define in the classic report designer. A basic requirement for creating RDLC report layouts is to first create a logical design: specify the data items and link them in the right way. Meaning: the logical design is shared by both report layouts. You must also use the classic report designer to decide what to display on the report – but not where to display it. Only data that is added to sections in the classic report designer is available in Visual Studio Report Designer. Fields and other data can be added wherever you like in sections – as long as the data is there, visible or not. The new reporting layout is meant to serve multiple display targets; it will resize the pages and reports automatically based on the display target. After the logical design and the classic layout is finished, Visual Studio report designer can be used to place the data where you want it. Unlike the classic layout created in the Section Designer, the RDLC report layout is not a WYSIWYG layout. The Visual Studio report designer contains features that are not available in the classic report designer (colors, charts), and it also has limitations compared to the classic report designer. Remember that the Visual Studio Report Designer is just an option: if certain things cannot be achieved with the Visual Studio report designer, you can always use the classic designer. While the Classic client can still only run reports designed in the classic report designer, the new RoleTailored client can run reports designed with either the classic or with the VS report designer. When the RoleTailored client launches a report, it checks if a layout is defined in Visual Studio Report designer. If it is, then it will run that. If no layout is defined, it will launch the report engine from the Classic client and run the report exactly like it is run from a Classic client. This does require that a Classic client is installed as well, even if the user never has to run this client. The structure of a report in Visual Studio is different from the structure in the Classic client.
1-10
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports In the Classic client, a report can have multiple body, header and footer sections. A report in Visual Studio however always has exactly one Body section, and it is not possible to add more than one. Optionally it can have one Page Header and one Page Footer section. Extra headers or footers cannot be added. It is possible to enable the Header and Footer sections by right-clicking in a blank report area, then enabling or disabling the Page Header and Page Footer sections. When disabling a Page Header or Page Footer, the entire section is deleted. When the report runs, it runs the Header section once, then the Body section once, and then the Footer section once. It will not – like in the Microsoft Dynamics NAV report designer – run the Body section for each record. Looping through records is done by creating a table in the body section. More information on tables is discussed later on in this material. However, there is one other limitation that concerns the Header section in the Visual Studio Report Designer. In Page Header sections, it is not possible to work with data fields. This is different from the Classic client, where data coming from fields, variables or functions in any section can display. (Chapter 3 describes how to use expressions and custom coding to work with data fields in the header and footer.) More information on designing classic reports can be found in Course 80042A, C/SIDE Introduction in Microsoft Dynamics® NAV 2009.
Tables The Table control is available in the Toolbox and can be used to loop through data in a table. To create a table, insert it from the toolbox. As default it will have a Header, Detail and Footer section. To enter something in a cell, either rightclick it, select Properties, and specify Value; or drag and drop items from your Data set. Remember that your data set ("Website Data Sources") consists of what you have added to the sections in the classic report designer. A table can have several sections: Table Section Type
Description
Header
This is a typical place to put captions. If you drag an item containing text from your data set into a header, the environment automatically adds "First" to it. "First" means that it will show the first value in the data set, as opposed to looping through each record in the data set.
Detail
This is where you have the iteration of the data in the report.
Footer
This is a typical place to put totals. If you drag an item containing a numerical value from your data set into the footer, the environment automatically adds "Sum" to it, and the report will print the total from the report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-11
Report Design in Microsoft Dynamics® NAV 2009 The table sections can be used as an alternative for some of the header and footer sections that are not supported in the RoleTailored client. What about reports with multiple indented data items? As the Visual Studio Report Designer only allows for one body section, how can data from multiple data items be displayed? The answer to this question is found in another difference between the classic and the Visual Studio Report Designer: the way the dataset is generated.
Rules for Flattening Data Unlike the classic report, the RoleTailored client report works with a flattened dataset. This means that data from multiple tables is joined before it is sent to the client. The rules for flattening data can be described as follows: •
Reports with one data item: This corresponds to a single SELECT Column FROM Table statement. The result can be displayed in the body section.
•
Reports with indented data items: This is very similar to SELECT Column FROM Table A INNER/OUTER JOIN Table B ON Table A.Column = Table B.Column. If PrintOnlyIfDetail is set to True on the parent, an INNER join is used. If PrintOnlyIfDetail is set to False on the parent data item, an OUTER JOIN is used. The resulting set can then be displayed using grouping and filtering.
•
Reports with multiple data items on the same level: This corresponds to a UNION statement. Again, grouping and filtering can be needed to display the correct records.
The following dataset generation in both clients is explained based on an example. In this example, three posted sales invoices will be printed. The first sales invoice header, Invoice No. 1001, has four sales invoice lines of (Type = Item) to which two different VAT percentages apply. The second sales invoice (1002) has one line and is sold without VAT. The third invoice (1003) has one line, to which one single VAT percentage applies. When you run the report in the Classic client, Microsoft Dynamics NAV will start retrieving the first sales header. For this invoice, it will sequentially get the corresponding sales invoice lines (four lines) and calculate the VAT Amount Line (two lines). Next, the VAT specification lines (two lines in this case) will be retrieved. After the last data item for the first sales invoice header is finished, it will proceed to invoice 1002 and repeat the same logic. Finally, it will pass to the third sales invoice header and execute the same scenario. As a result, when the report is run in the Classic client, it retrieves three separate recordsets three times. The recordsets come from three tables (Sales Invoice Header, Sales Invoice Line, and VAT Amount Line) with a different table structure. As soon as the information is available, the report is printed.
1-12
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports In the RoleTailored client, the dataset is generated in another way. The RoleTailored client works with a flattened dataset, which means that tables will be joined (in reports with multiple tables). The result of the queries will be one single dataset containing information from multiple tables. As soon as the dataset is available, the dataset can be processed using filtering and sorting and the report can be rendered. In the following figure, the dataset will look like this (not all fields from the sales invoice report are included):
FIGURE 1.3 DATASET GENERATION IN THE ROLETAILORED CLIENT
The dataset combines information from three tables. For invoice 1001 six lines are included. Invoice 1002 has only one line, and invoice 1003 has two lines. The first four lines for Invoice 1001 relate to the four sales invoice lines. The two other lines represent the VAT specification lines for the Invoice. To generate the dataset, the logical model of the report is used. To select records from a single table, a simple SELECT statement is used. In this case, if the report contains several unindented data items, the tables will be merged using a UNION statement. The resulting recordset contains the fields from all data items in the report. When selecting records from multiple linked tables, the SELECT statement must be extended with a JOIN clause. As a result, in reports with indented tables, data items will first be joined using the conditions specified in the DataItemLink property. In this case, the Sales Invoice Header and the Sales Invoice Line table will be joined, and all relevant fields will be selected.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-13
Report Design in Microsoft Dynamics® NAV 2009 After handling the sales invoice lines, the report will proceed to the next data item. (In this example, it is assumed that no dimensions are specified.) Next, it will try to retrieve the VAT Amount Lines. Again, the Sales Invoice Header and the VAT Amount Line data items will be joined and the relevant fields will be selected from the data item. So far, several recordsets are now generated in the example. As a final step, these smaller recordsets will be merged through a UNION statement. As a result, the Sales Invoice Line and the VAT Amount Line recordsets will be merged into a recordset containing fields from all three tables, which results in the dataset that is shown.
Creating and Transforming the Layout This lesson describes how a report is designed and executed in the Classic and in the RoleTailored client.
Creating the Layout - Classic In the Classic client, a report is completely created in the C/SIDE development environment, using the Object Designer. In a report description, you can distinguish between two major design parts: the logical design and the visual design. The logical design is created in the Report Designer. In the Report Designer you specify the data items to include in the report, and the relationship between the data items. In addition, here filters, sorting, grouping and totaling are also defined, just like specific output options (page size, page orientation). The visual design is created in the Section Designer and defines the information that you want to be printed on the report and its formatting (height, width, position). For processing-only reports no visual design can be created. When the report is created and saved, make it accessible by adding it to a form or to a menu suite (or run it using code from any other object). From the form or the menu, the report can be run in preview mode or sent to a printer.
1-14
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports When the report is executed, data is fetched quickly from the server, formatted and presented by the client as soon as the data is available. For every data item, records are fetched sequentially. In case of indented data items, the child data items are processed for each record in the parent data item. If there are large data volumes, running a report can result in slow report execution.
FIGURE 1.4 REPORT CREATION WORKFLOW IN THE CLASSIC CLIENT
Demonstration: Creating the Classic Design Using The Wizard Rebecca, the receptionist, has asked Mort to provide her with a list containing some contact information for all employees. Mort is a business applications developer who has access to the Microsoft Dynamics NAV environment. Rebecca wants to have a list with the following information: •
Employee No.
•
First Name
•
Last Name
•
Phone No.
•
Mobile Phone No.
•
E-Mail Address
•
Employment Contract Code
Rebecca wants to have the list sorted alphabetically by last name. Mort has basic knowledge of the C/SIDE environment. He will create a new report using the Report Wizard. 1. 2. 3. 4.
Select Tools, Object Designer. Click the Report button. Click the New button. In the Table field, select table 5200, Employee.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-15
Report Design in Microsoft Dynamics® NAV 2009 5. Select Create a report using wizard. 6. Select Tabular-Type Report Wizard. 7. Click OK.
Adding Fields 1. In the left listbox, double-click the No., First Name, Last Name, Phone No., Mobile Phone No., E-Mail Address and Employmnt. Contract Code fields. 2. Click the Next button
Sorting and Grouping Data 1. Select the Yes I want my data sorted according to the following option. 2. Select the Last Name, First Name, Middle Name key. 3. Click the Next button. 4. Select No I don't want to group my data. 5. Click the Next button.
Choosing a Document Style 1. Select the List Style option. 2. Click the Finish button.
Save the Report 1. Select File, Save As. 2. In the ID Field, enter 60000. 3. In the Name field, enter Rebecca's List
Creating the Layout - RoleTailored Client In the RoleTailored client, the scenario is slightly different. The main idea behind the new reporting functionality is to preserve compatibility with version 5.0 while taking advantage of the new reporting functionality of SQL Server Reporting Services.
1-16
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports The starting point for the RDLC report layout is the same as in the Classic client: the Report Designer.
FIGURE 1.5 REPORT CREATION WORKFLOW IN THE ROLETAILORED CLIENT
Reports for the RoleTailored client also start from a logical design that is created in the Report Designer. This is the same as for the Classic client. However the RDLC report layout is not created in the Section Designer; it is created outside Microsoft Dynamics NAV 2009, namely in Visual Studio. Instead of calling the Section Designer and creating traditional sections, the designer will have to create and edit the report layout using the Microsoft Visual Studio IDE. The Visual Studio IDE can be opened by calling View, Layout in the Report Designer. (If the report does not have an RDLC layout, Visual Studio will open and show a blank layout.) Here you can create or edit the report layout to fit your needs. As soon as the designer is finished editing the report in Visual Studio, the designer can exit Visual Studio and return to the Report Designer. The Report Designer will automatically detect any changes to the RDLC report layout and display a dialog box which allows you to save or discard the changes. When you choose to save the changes, the newly created RDLC report layout will be imported into the Classic object, thereby overwriting the previous version of the RDLC layout. Finally when exiting the Report Designer, the user can again choose to save the report or to discard the changes. When you discard the changes to the report object, the newly imported RDLC report layout is not saved. Reports that are created for the RoleTailored client can be run in a number of ways. More information on how to run reports will follow in Chapter 5.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-17
Report Design in Microsoft Dynamics® NAV 2009 Demonstration: Creating the RDLC Report Layout Rebecca has become a RoleTailored client user. She asks Mort to create an RoleTailored client version of the "Rebecca's List" report. Rebecca asks for a small change to the classic report: she wants to have the Last Name field to appear as the first column in the list. Mort decides to build the report from scratch 1. 2. 3. 4. 5.
Select Tools, Object Designer. Click the Report button. Select the report named "Rebecca's List". Click the Design button. Select View, Layout.
The RDLC report layout will now be opened in Visual Studio. Mort is ready to start builiding the report.
Demonstration: Creating the RDLC Report Layout Adding a Table Mort starts building the report for Rebecca. He starts by adding a table data region control to the report. Next he adds the necessary fields to the report. 1. In the Toolbox window, select the Table control. 2. Click the upper left corner in the body section to insert a table.
Demonstration: Creating the RDLC Report Layout Adding Table Columns Mort notices that the default table has three columns and three rows. Since this is not sufficient for his list, he adds four new columns to the table. 1. Right-click any cell in the table and choose Select 'table1' (where table1 is the name of the newly added table control). 2. Right-click the shaded border of the table control and select Add Column. 3. Repeat steps 1 and 2 two times.
Demonstration: Creating the RDLC Report Layout Adding Fields Mort starts adding the necessary fields to the report. 1. In the Website Data Sources window (the dataset), select the Employee__Last_Name_ element. 2. Drag it to the first cell on the second row of the table.
1-18
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 3. In the dataset, select the Employee__First_Name_, Employee__Phone_No__, Employee__Mobile_Phone_No__, Employee__E-Mail_Address_ and Employee__Emplymt__Contract_Code_ field and drag these to the next columns of the table.
Demonstration: Creating the RDLC Report Layout Closing Visual Studio When Mort is finished, he is ready to close the Visual Studio Report Designer and import the RDLC report layout in the classic report. 1. Select File, Exit or click the Close button to exit Visual Studio. 2. Click Yes to save the modified files. 3. In the Report Designer, select either a blank line or another data item (a data item that differs from the current selected data item). A warning message will be displayed stating that the report layout has been changed by another application, and asking to load the changes or not. 4. Select Yes to load the changes. 5. Select File, Save or press Ctrl+S to save and compile the object in the Object Designer. 6. Click Yes to save the changes to the report.
Demonstration: Creating the RDLC Report Layout Using the Create Layout Suggestion Function As he is about to finish the report for Rebecca, Mort gets a telephone call from his manager Tim. He asks Mort to give high priority to a problem that is reported by Susan. Mort exits Visual Studio, and by accident, he forgets to save his changes. Half an hour later, Mort is back at his desk. He decides to use the Create Layout Suggestion function now. 1. Select Tools, Object Designer. 2. Click the Report button. 3. Select the report named "Rebecca's List".
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-19
Report Design in Microsoft Dynamics® NAV 2009 4. Click the Design button. 5. Select Tools, Create Layout Suggestion.
FIGURE 1.6 THE CREATE LAYOUT SUGGESTION FUNCTION
Modifying the Layout 1. Select the column containing the Last Name field (the third column) . 2. Drag it to the first column. 3. Select the second column (containing the Employee No. field) 4. Press Delete.
Closing Visual Studio 1. Select File, Exit or click the Close button to exit Visual Studio. 2. Click Yes to save the modified files. 3. In the Report Designer, select either a blank line or another data item (a data item that differs from the current selected data item). A warning message will be displayed stating that the report layout has been changed by another application, and asking to load the changes. 4. Select Yes to load the changes. 5. Select File, Save or press Ctrl+S to save the object in the Object Designer.
Executing a Report Not only is the creation of reports different for the Classic and the RoleTailored client, but also the execution of reports. The most important changes are the components used by each client, the execution of the business logic and the way data is queried. In the Classic client, the report is executed using three components of the report object: •
1-20
The data items (which make up the dataset)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports •
The sections (which make up the layout)
•
The request form (eventually)
The Classic client is responsible for data retrieval, business logic execution, and data presentation. Data retrieval is based on the structure of the report: dataitems on the same indentation level are processed in a sequential way. In reports with indented dataitems, the dataitems on the child level are retrieved and processed before the next record of the parent dataitem is retrieved. The RoleTailored client will use the data items of the report object, but it will use the RDLC layout definition (instead of the sections) and the request page (instead of the request form). In addition, in the RoleTailored client all business logic will be executed by the service tier and its components and it works with a flattened dataset (which means that tables are joined). The following figure shows how reports are executed in the RoleTailored client:
FIGURE 1.7 REPORT EXECUTION IN THE ROLETAILORED CLIENT
When a user runs a report from the RoleTailored client, the report object is initialized on the service tier. As a result the service tier sends the request page back to the RoleTailored client, where it is rendered and displayed. Next, the user can enter filters in the request page. When the user clicks the Preview or the Print button, the report execution is started. The reporting runtime on the Service Tier uses the report description to request data from the database. As soon as the reporting runtime receives the data, it starts executing the business logic (defined in C/AL code) and flattening the data. Afterwards, the flattened dataset and the RDLC file are sent to the client. Finally, the report will be rendered on the RoleTailored client by the ReportViewer control.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-21
Report Design in Microsoft Dynamics® NAV 2009 RDL versus RDLC Report Definition Language (RDL) is an XML-based schema for defining reports. The goal of RDL is to promote the interoperability of commercial reporting products by defining a common schema that allows interchange of report definitions. RDL files contain both data query and presentation specifications. To interpret and execute RDL files, an advanced reporting tool such as Microsoft SQL Server Reporting Services is needed. RDL reports can only be accessed through and produced on a reporting server. This is called server-side reporting. An alternative reporting technology is client-side reporting. With this technology, reports are produced on the client using a ReportViewer control. Microsoft's ReportViewer control is a freely distributable control that allows embedding reports in custom applications. The ReportViewer control is capable of generating, rendering, printing, and saving reports without an advanced reporting tool. For more information about the ReportViewer control; refer to Chapter 5. The difference between an RDL and an RDLC file is fairly simple: RDLC files do not contain any data query information (unless they are converted from an RDL file). Both files can be created using specific development tools such as Microsoft SQL Server's Business Intelligence Development Studio or Microsoft Visual Studio. Conversely, RDL files can be converted to RDLC format. For more information on the ReportViewer control check out http://msdn.microsoft.com/en-us/library/ms252109(VS.80).aspx. For more information on converting RDLC to RDL format, see http://msdn.microsoft.com/en-us/library/ms252109(VS.80).aspx.
Transforming the Layout Since the RoleTailored and the Classic client are using different report components, creating reports for the RoleTailored client will require additional design activities. In fact, the only common component between both layouts is the dataset. The other components, the request pages and the RDLC data need to be designed separately. Once the Classic report is defined, you can start defining the RDLC report layout. While the Classic layout is built using the C/SIDE environment and its controls, the RDLC report layout will be built using the Visual Studio IDE. Although the content of the report is normally the same for both user types, the layout of the reports can be completely different. Not only can the layout be different, but also the controls that are used. In the RDLC report layout, you can use almost all reporting-related controls that are available in the Visual Studio IDE, even controls that are not available in the Classic toolbox (such as a Chart).
1-22
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports To create a report for the RoleTailored client, there are two options: •
Start from scratch;
•
Use the built-in layout suggestion function. This function will create both a layout suggestion and a dataset based on the design of the classic report.
The layout suggestion will be presented in the VS IDE. In Visual Studio you can further edit and fine-tune the layout, using the available controls and dataset items. As already mentioned previously, the dataset is generated based on the classic design. The idea is to treat each label and textbox as a separate column in the resulting dataset. The following rules apply: •
The primary key for all dataitems in a dataset is added even if the fields are not referenced in sections.
•
Columns used for groupings are added to the dataset even if they are not referenced in sections.
•
Format strings for controls containing currency amounts (decimal values) are added to be able to have the amounts formatted in the same way they are defined in the G/L Setup window in Microsoft Dynamics NAV 2009.
Furthermore: •
Label controls in any section will turn into a DataSet field.
•
TextBox controls in all header sections will turn into a DataSet field.
•
TextBox controls in all body sections will turn into a DataSet field.
•
TextBox controls in all group header sections will turn into a DataSet field.
•
TextBox controls in all transheader and transfooter sections will not turn into a DataSet field.
•
TextBox controls in all group footer and footer sections will not turn into a DataSet field if a matching source expression is found on a control in the body section.
•
PictureBox controls follow the same rules with the TextBox controls
•
Shape controls are ignored.
•
If a textbox is of type Decimal an extra field is added for formatting.
•
If a control in the C/SIDE layout has a No value for its Visible property it will appear in the dataset. (This allows adding new controls to the Classic layout for easing transformation without changing the C/SIDE runtime behavior.)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-23
Report Design in Microsoft Dynamics® NAV 2009 Simple rules apply to the naming of the elements in the dataset: •
Each control is prefixed with the name of the dataitem.
•
Totals will not be added to dataset.
•
Controls that appear with the same source expression in several sections will be added once.
The naming of the elements can be defined by setting the DataSetFieldName property on the corresponding control (in the Section Designer). In the classic report designer, there is "instant access" to the data model. This easily allows the addition of extra data items to the report (causing extra sections to be added immediately), after which you can continue working. In the Visual Studio Report Designer, this is different. The dataset is built when Visual Studio is opened and cannot be refreshed. To have the dataset changed, you have to leave the RDLC report layout and return to the Report Designer. After changing the classic layout, you can reopen the report in Visual Studio.
Microsoft Visual Studio The Visual Studio development system is a comprehensive suite of tools designed to help software developers create innovative, next generation applications. In Microsoft Visual Studio, applications can be built for a: Windows Client, Web, Microsoft Office system, .NET Framework, SQL Server, and Windows Mobile using integrated drag-and-drop designers. Microsoft Visual Studio supports multiple programming languages (Visual Basic, C#, C++, by means of language services. When installing Microsoft Visual Studio, choose the programming language you want to use. Support for other languages can be added by installing the language services separately. It also supports XML/XLST, HTML/XHTML, JavaScript and CSS for Web development projects. Microsoft Visual Studio ships in different editions: Visual Studio Express Editions: Visual Studio Express Editions are a set of lightweight editions of the Visual Studio IDE. Visual Studio Express Editions are delivered based on each language and offer a smaller set of tools than the other editions. (For example, x64 compilers are not available). VS Express Editions are targeted to hobbyists and students. Visual Studio Standard: Visual Studio Standard is targeted to individual developers and small teams who want to create connected applications with next generation experiences. Like Express Editions, Visual Studio Standard offers simplified menus; however it offers more features than Express Editions.
1-24
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports Visual Studio Professional: This is intended for development teams who create projects that target the Web (including ASP.NET AJAX), Windows Vista®, Windows Server® 2008, Microsoft Office 2007, Microsoft SQL Server® 2008 and Windows Mobile® devices. Visual Studio Professional offers full menus and full Microsoft SQL Server integration. Visual Studio Team System: Microsoft Visual Studio Team System 2008 is an integrated application lifecycle management (ALM) product family. It contains the tools and processes that helps software teams by improving communication and collaboration throughout the software development process. Visual Studio Team System comes with several suites targeted at the different roles or members involved in software development projects. It offers a full user experience, support for Itanium processors, additional management features such as team reporting, and team portals.
The Microsoft Visual Studio Integrated Development Environment (IDE) The Visual Studio product family shares a single integrated development environment (IDE) that is composed of several elements: the Menu toolbar, Standard toolbar, various tool windows docked or auto-hidden on the left, bottom, and right sides, as well as the editor space. The tool windows, menus, and toolbars available depend on the type of project or file you are working in.
Menu Bar The menu bar appears at the top of the IDE and gives access to all features and commands in the Visual Studio IDE. Some familiar menu names are File, Edit, View, Tools, Window and Help. Each menu contains commands and command groups. Commands are functions that either launch submenus or accomplish tasks, such as printing a document, refreshing a view, or creating a new file. Depending on the type of project you are creating, new menus can appear (Format, Web site, Data, and Report).
Toolbars Toolbars are normally displayed at the top of the IDE, under the menu bar, but can be moved and docked to the left, right or bottom side of the IDE. Toolbars are normally displayed at the top of the IDE, under the menu bar, but can be moved and docked to the left, right or bottom side of the IDE. Toolbars typically are rows of buttons and other controls (such as combination boxes, list boxes, text boxes, and splitter controls) that are associated with commands. When you click a toolbar button, its associated command is activated. Toolbar buttons usually have icons that suggest the underlying commands, such as a printer for a Print command. Like menus, toolbars are convenient graphical ways to present commands to users. Typically, related commands are clustered together on the same menu or toolbar.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-25
Report Design in Microsoft Dynamics® NAV 2009 By default, not all available toolbars are displayed. To add additional toolbars, select View, Toolbars and check the toolbars to display. From the same menu, you can also choose to create new toolbars.
Editors and Designers Microsoft Visual Studio includes multiple editor and designers that depend on the type of file or document that you are authoring. The Text editor is the basic word processor of the IDE, while the Code editor is the basic source code editor. Other editors, such as the CSS editor, the HTML Designer, and the Web Page Designer, share many of the features found in the Code editor, along with enhancements specific to the type of code or markup supported. Editors and designers usually have two views: a graphical design view and the code behind view (or source view). Design View lets you specify the location of controls and other items on the user interface or Web page. You can easily drag a control from the Toolbox and place it on the design surface. Source View displays the source code for the file or document. This view supports coding help such as IntelliSense, collapsible code sections, code refactoring, and code snippet insertion. Other features include bookmarks and displaying line numbers, to name a few. Some editors, such as the Web Page Designer and HTML Designer, also provide a hybrid view which lets you see the graphical and code view of a file simultaneously. This view is called Split View. In the editor, you can have multiple files opened at a time. For each file that is opened in a project or solution, the code editor will contain a tab. You can easily switch from one file to another by clicking the tab.
Solution Explorer The Solution Explorer displays solutions, their projects, and the items in those projects. From Solution Explorer, you can open files for editing, add new files to a project, and view solution, project, and item properties.
Properties Editor The properties window contains all properties for the item that is selected in the editors or designer. At startup, the window will show the properties of the field that is selected in the Solution Explorer. The contents of the window will be refreshed when you select another file in the Solution Explorer, or any object in the designers (textbox, table row, and so on). When working in the code editor, you will see the name of the code trigger that is being edited.
Server Explorer The Server Explorer is a new development tool in Microsoft Visual Studio® .NET or in Microsoft Visual Studio 2005 that is shared across development
1-26
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports languages and projects. With the Server Explorer, you can connect to servers, and view and access their resources. For example, you can connect to, view and access the following resources: Database Connections, Servers, Crystal Reports, Event Logs, Message Queues, Performance Counters and Windows Services. The Server Explorer is not used when creating reports for the RoleTailored client.
Toolbox The toolbox contains a list of controls that you can add to the design view of the project. The contents of the Toolbox will vary depending on the type of project you are editing. To add controls from the toolbox to your project, drag and drop it to the design view. You can add new controls to the Toolbox by right-clicking on the toolbox and selecting Choose Items. The toolbox window is often autohidden.
Report Properties When designing reports in Microsoft Dynamics NAV, you can achieve good results without even writing a single letter of code. Much can be done using properties. This lesson describes some properties that are frequently used in the Classic client report.
Report Properties Properties occur on many different levels in the report description. The following list shows the properties on the report level that are frequently used when designing reports.
UseReqForm You can use this property to decide whether the user of the report will be presented with a request form or not. If UseReqForm is set to No, no request form will be shown. This implies that the user will not be able to choose a sorting order or to set filters and that the print dialog will not be shown (that is, a report will be printed immediately). This property overrules any request form or request page from the report.
ProcessingOnly This property is used to set whether a report will produce printed output, or will only be able to process data. This property is not allowed to insert controls in any section when ProcessingOnly is set to Yes.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-27
Report Design in Microsoft Dynamics® NAV 2009 If ProcessingOnly is set toYes, it is not possible to insert an RDLC layout. In addition, the Print and Preview buttons in the request options form or page are replaced by an OK button. No output is produced. (Any RDLC data part will be removed when setting the property to Yes.) TopMargin,BottomMarginLeftMargin,RightMargin: Use these properties to set the margins of a report. The unit of measure is 1/100 mm. Margins specified in the page setup dialog will override these properties. Some printers require a minimum margin. If you specify a margin that is smaller than the minimum margin, the minimum margin will be used when printing. These properties are ignored in the RoleTailored client. PaperSize and Orientation: The PaperSize property allows you to select a specific paper format for the report. If no specific paper format is specified, the report will use the default paper size of the printer. Some well-known paper sizes are A4, Letter, and German Fanfold. The Orientation property is used to define whether the report needs to be printed in landscape or in portrait page orientation. It is used in combination with the PageSize property. If no specific orientation is selected, the default orientation from the printer will be used. Since the new reporting solution is built to support multiple clients and display targets, it uses the ReportViewer control. This is an intelligent control that is capable of rendering the report output based on the display target that is used. As a result, in the RoleTailored client, properties like PaperSize and Orientation are now obsolete.
Data Item Properties The following list shows the properties on data item level that are frequently used when designing reports.
DataItemTableView Use this property to define the key, sort order and the filter for this data item. If a key is selected, the users of the report will not be able to select any key, sorting order or filters for that data item. As a result, there will be no tab for the current data item in the request form or page. If a sorting order is selected, it is suggested as the default if the users of the report select a sorting order.
1-28
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports If a filter is selected, it is used together with the filters that the user specifies in the request form. Selecting a sorting order or a filter, or both, does not inhibit the user from selecting a key. The DataItemTableView property is a very important property for grouping data and calculating totals in the Classic client. This property is part of the logical design and applies to both the Classic and the RDLC report layout.
DataItemLinkReference Use this property to specify the data item on a higher level for the indented data item it will be linked to. When you specify DataItemLinkReference, use the DataItemLink property to specify one or more fields from each data item to base the link on. This property is part of the logical design and applies to both the Classic and the RDLC report layout.
DataItemLink Use this property to specify the corresponding fields from two data items that are linked by the DataItemLinkReference property. The link is defined as a property of the indented data item. This property is part of the logical design and applies to both the Classic and the RDLC report layout.
NewPagePerRecord Use this property to determine whether a page break will be generated after each record of the data item is printed. This property is ignored by the RDLC report layout. To insert a page break for each record in the RDLC report layout, you have to set the properties of the Table control.
GroupTotalFields Use this property to specify those fields of a data item that are used to group records. The GroupTotalFields and the TotalFields properties can be used in conjunction to maintain totals for one or more fields, and both the group totals and the grand totals can be output by using the appropriate sections (GroupHeader and GroupFooter). You can specify a comma-separated list of fields.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-29
Report Design in Microsoft Dynamics® NAV 2009 The property is ignored by the RoleTailored client. In the RoleTailored client, you can work with table or group headers to automatically display groupings. No special key or DataItemTableView is required.
TotalFields Use this property to indicate the fields of a data item that the system maintains totals for. If this property is used in conjunction with the GroupTotalFields, totals can be maintained for both the groups that are defined and all records that are output. If it is used by itself, TotalFields will maintain totals for all records. You can specify a comma-separated list of fields. The property is ignored by the RoleTailored client. In the RoleTailored client, you can work with table or group footers to automatically display totals. No special key or DataItemTableView is required.
PrintOnlyIfDetail Use the PrintOnlyIfDetail property to limit printing a data item that does not have a detailed data item. This property is not available in the RoleTailored client, but it is evaluated when flattening the data. If the property is shown as False on the parent data item, the system uses an outer join select statement.
ReqFilterFields Use this property to indicate those fields that will automatically be included on the tab of the request form that pertains to this data item. The user can set filters on these fields. When the request form or page is in use, the user will be able to add other fields and set filters on these fields. Even so, it it still recommended to use this property. If the underlying table has many fields the occasional user of the report may not easily find the relevant fields to filter. If the user is not going to be able to put filters on other fields, you must remove the request form altogether by using the UseReqForm property of the report, or remove the tab for this data item, by setting a specific key in the DataItemTableView property. This property is part of the logical design and applies to both the Classic and the RDLC report layout.
ReqFilterHeading Use this property to create a caption for the request form tab that pertains to this data item. You can specify captions in different languages using the ReqFilterHeadingML property. This property is part of the logical design and applies to both the Classic and the RDLC report layout.
1-30
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports Section Properties The following list shows the properties on section level that are frequently used when designing reports. Sections only have a few properties, and as they are replaced by the RDLC data component, they will in most cases be ignored.
PrintOnEveryPage Use this property to indicate whether a header or footer section must be printed on every page or only on the first (headers) or the last (footers). This property is ignored by the RDLC report layout. To have sections printed on every page, you can set the RepeatOnNewPage property for the (table and/or group) headers and footers in Visual Studio.
SectionHeight and SectionWidth Use these properties to set the height and the width of the different sections in the Classic client. Since the new reporting solution is built to support multiple clients and display targets, it uses the ReportViewer control. This is an intelligent control that is capable of rendering the report output based on the display target that is used. As a result, in the RoleTailored client, properties like SectionWidth and SectionHeight are now obsolete.
What about Section Triggers? Section triggers like OnPreSection and OnPostSection do not exist in the RDLC layout. In Classic reports, these triggers are often used to print or hide sections based on specific conditions. Since these triggers are not available in the new reporting solution, all code that is written in these triggers in the Classic report must be moved to other places in the report, to support the same functionalities in both layouts. This is described further in Chapter 3.
Report Functions Apart from the properties, there are a number of statements that are often used in Classic reports.
CurrReport.NewPage Use this function to force a page break when printing a report. This statement is ignored by the RoleTailored client.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-31
Report Design in Microsoft Dynamics® NAV 2009 CurrReport.ShowOutput Use this function to return the current setting of whether a section is outputted or not, or to change this setting. This statement is often used in the onPreSection trigger of a specific section to have the section printed (or not) based on a specific condition. This is not supported in the RDLC report layout. To obtain the same functionality in the RoleTailored client, include a variable that you use in combination with the Visible property of a specific control.
CurrReport.CreateTotals Use this function to maintain totals for a variable or a field in the same way as totals are maintained for fields by using the TotalFields property. Use the TotalFields property to calculate totals for each group on a specific level. Use the CREATETOTALS function to maintain grand totals over the different levels in a report. In the RoleTailored client, this statement is now obsolete, since grouping and totaling are supported by using footers and headers.
Building the Request Form/Page When a report is run, the request form is displayed. The request form is a special window that allows the user to define output options for the report. In some cases there is an extra tab called Options, which is not related to a data item. It contains general information that determines the output and the execution of the report. The request form is displayed when the report is run in the Classic client and the request page is displayed when the report is run in the RoleTailored client. They have the same purpose which is to let the user provide additional input before previewing or printing the report.
The Request Form When a new report is created, a request form is automatically created for the report. By default, the request form will contain a tab for each data item in the report. The tabs cannot be visualized in design time; they will be available in runtime. The content of the data item related tabs can be defined by setting the properties (ReqFilterFields, DataItemTableView...) of the data items.
1-32
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports In addition, custom options for the report can be created on a special tab in the request form: the Options tab. These custom options are designed by using the Request Options Form Designer which is accessed from the Report Designer. The following steps show how to open the Request Options Form Designer. 1. Open the Report Designer from the Object Designer. 2. In the Report Designer, click View, Request Form. Only the Options tab of the request form can be customized. The rest of the tabs which correspond to the data items cannot be modified, although they can be hidden by sorting the data item (setting the DataItemTableView property) and clearing the ReqFilterFields property of the data item. Designing the Options tab is similar to designing any other form: you can add any control from the toolbox to it, and even add some coding in the form triggers. The Options tab is always displayed as the last tab of the request form, and is displayed only if there are controls in it. To hide the Options tab, remove any controls from the request form. For more information on how to design and edit the Request Form, refer to the C/SIDE Introduction in Microsoft Dynamics® NAV 2009 MOC.
The Request Page The request page has the same purpose as the request form. It is displayed when the report is run in the RoleTailored client. When a new report is created, a request page is automatically created for the report. In addition, custom options can be created in the request page. These options are designed by using the Request Options Page Designer which is accessed from the Report Designer. The following steps show how to open the Request Options Page Designer. 1. Open the Report Designer from the Object Designer. 2. In the Report Designer, click View, Request Page. The Request Options Page Designer is similar to the Page Designer. Here developers can add controls, such as FastTabs and fields to the request page. Controls that are created in the Request Options Page Designer are always displayed above the FastTabs that correspond to data items. For more information on how to design and edit the Request Page, refer to the C/SIDE Introduction in Microsoft Dynamics® NAV 2009 MOC
Demonstration: Open the Request Page Susan,who's talking to many customers during her daily job, has another request for Mort. Some customers would like to have item pictures included on the sales quote document. She asks Mort if it is possible to include this as an option on the Request Options Page. Mort agrees to change the request options page. 1. Select Tools, Object Designer.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-33
Report Design in Microsoft Dynamics® NAV 2009 2. 3. 4. 5.
Click the Report button. Select report 204, Sales - Quote. Click the Design button. Select View, Request Page.
Mort is now ready to change the request options page.
Request Form Transformation The Classic reporting engine is based on the two-tier architecture: the business logic is executed and the report is rendered completely on the client side. In the new architecture, the business logic is executed on the service tier, and the client is only responsible for rendering the report output. Since the new RoleTailored client uses Microsoft SQL Server Reporting Services features and pages to display data, creating the RDLC report layouts will also include creating a request page. There are two options to create a request page •
either you start with a blank page and you build the request page yourself in the request option page designer (View, Request Page);
•
either you convert the request form into pages (like you do with Classic forms). In this case you use the Form Transformation Tool to transform the request form for the Classic report into a request page.
Note that using the Form Transformation Tool can sometimes be more timeconsuming than building the request page from scratch. The RoleTailored client can run classic reports as well. By default, the RoleTailored client first looks for the RDLC reprot layout, but if this is not present, you can run classic reports from the RoleTailored client. In that case, the RoleTailored client uses the runtime of the Classic client to run the report (provided that the Classic client is also installed on the same computer).
Sorting Data Data can be sorted in many ways. In Microsoft Dynamics NAV, each possible sort order is directly related to a table key. Meaning, you can have as many sortings as there are keys in your table. You can define up to 40 keys (one primary, 39 secondary keys) in a table.
1-34
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports Sorting can be defined in a number of ways in the Classic client: •
Use the DataItemTableView property to define the sorting of a data item. Select any of the keys that are defined in the table and also determine the sorting order (ascending or descending). Sorting methods that are defined here cannot be modified by the user. When specifying a Key in the DataItemTableView property, notice that the Sort button is removed from the request options form. In addition, the tab for the corresponding data item disappears from the request form (unless request filter fields are specified in the ReqFilterFields property of the same data item).
•
Let the user decide how the data will be sorted. In this case, do not specify a Key in the DataItemTableView property of the data item. (Specify the Order if necessary.) When printing a report, the user can click the Sort button and define both the Key and the Order to use in the Sort window. Remember that the Order selected in the Sort window will overrule the Order specified in the DataItemTableView.
•
Use coding to define the sorting programmatically. One way is to define the sorting hardcoded in the AL Code using the SETCURRENTKEY statement. An alternative and more flexible solution is to let the user select from a limited set of sorting methods on the request options form (and then tie the options to a specific SETCURRENTKEY statement). Remember that programmatic sorting overrules the sorting defined in the Sort window or the DataItemTableView property.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-35
Report Design in Microsoft Dynamics® NAV 2009 The three methods for sorting data apply to both the Classic and the RoleTailored client. The RDLC report layout offers another option to sort data. In Visual Studio you can specify additional sorting methods for any matrix or table control. To do this, right-click on a table or matrix control and select Properties. On the Sorting tab, define a custom sorting order:
FIGURE 1.8 ADDITIONAL SORTING DEFINED IN THE TABLE PROPERTIES WINDOW
You can even specify sorting options that do not match an existing key. For example, you can have your sales orders list sorted on Order Date, although the Sales Header table does not contain a corresponding key. NOTE: In the Classic client, you can only sort based on active keys. In the RoleTailored client reports, you do not need the Microsoft Dynamics NAV keys.
Filtering Data Filtering allows the user to limit the data that is included in a report and can be done in a number of ways: •
1-36
Use request filter fields: Request filter fields offer a variable way of filtering information. The user can decide whether or not to apply any filters. If any filter is specified, it is applied. If no filters are specified, all information is available. The advantage is that it allows the designer to solve multiple reporting needs with one and the same report. The disadvantage is that the user can set any filters and possibly manipulate the report output.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports •
Use the DataItemTableView property to set a filter on a data item inside the report. Filters that are defined inside a report cannot be removed. The filter in the DataItemTableView is not translated into explicit filtering criteria in the RDLC report layout. Instead the filter is applied on the service tier, before the dataset is sent to the client.
•
Use code to set some filters: Using code to set filters requires both programming skills and access to the C/AL Editor. Hardcoded filters can be set with the SETRANGE and SETFILTER statements. The disadvantage is that these filters are inside in the report and cannot be removed by the end user. The report can only serve specific purposes. The advantage is that the report output cannot be manipulated.
Filters that are set in any of these three ways apply to both the Classic and the RoleTailored client. Inside the Visual Studio IDE there is another way to define some filters. Additional filtering for the RoleTailored client can be defined by setting the properties of any Table or Matrix control. To define additional filter criteria, right-click on any table or matrix control, and select Properties. On the Filters tab, define the filters.
FIGURE 1.9 TABLE PROPERTIES WINDOW
Filters that are defined inside Visual Studio do not apply to the Classic version of the report, and they cannot be removed by the user.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-37
Report Design in Microsoft Dynamics® NAV 2009 As an alternative for defining hardcoded filters in the C/AL Editor, you can offer a more flexible way of filtering by using variables on the request form/ page and then use these variables as a filter. To be able to do this, the variables must be part of the dataset, which means that they have to be added invisibly to the classic design. Chapter 3 shows how to do this. In Microsoft SQL Server Reporting Services (SSRS), report parameters can be used to influence both data retrieval and data presentation. Although they can be defined in Visual Studio, they are not supported in the RoleTailored client.
Demonstration: Adding Sorting and Filtering Kevin, the Sales Manager, is using report 115, Salesperson - Commission, to calculate and monitor the performance of his salespersons. He notices that the report contains lines where all amounts are 0. He asks Mort to filter the report so that it only contains lines where both the Sales (LCY) and Profit (LCY) fields are different from 0. In addition, he wants the details sorted by Posting Date, in descending order. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
1-38
Select Tools, Object Designer. Click the Report button. Select report 115, Salesperson - Commission. Click the Design button. Select View, Layout. Select Table1 in the Body section. Right-click any cell in the table and choose Select 'Table1'. Right-click the shaded border and select Properties. Select the Sorting tab. In the Sort on field, select =Fields!Cust__Ledger_Entry__Posting_Date_.Value. In the Direction column, select Descending.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 11. Select the Filters tab. 12. In the Filter List, add the following criteria:
FIGURE 1.10 ADDITIONAL FILTER CRITERIA IN VISUAL STUDIO
13. 14. 15. 16.
Click OK to close the Table Properties window. Exit Visual Studio. Load the changes. Save and complile the classic report.
Mort is now ready to change the request options page.
Using the Wizard In the Classic client, there are two options to build a report: start from a blank report (and create the logical and visual report design manually) or build a report using the wizard. The wizard lets you select the data item to include, a report type (Form, Tabular, Label, and so on), the fields to add, grouping criteria, subtotals. As a result it will generate a layout for you including the fields and the necessary sections. The Report Wizard cannot be used to build advanced reports (including coding or pictures) and/or reports with multiple (indented) data items. The Report Wizard has always been a fundamental part of the Classic report designer. The Report Wizard is not available for the RoleTailored client. The classic Report Wizard is not capable of creating an RDLC file that can be used in Visual Studio. This implies that you always have to build a minimum report layout in the Classic design before building an RDLC report layout. The minimum layout must contain all data elements that you want to use in the RDLC report layout.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-39
Report Design in Microsoft Dynamics® NAV 2009 However, this does not mean that you have to build every report from scratch in Visual Studio. After you have finished your classic design, use the Tools, Create Layout Suggestion to automatically generate a layout suggestion for the RoleTailored client report. When using the Tools, Create Layout Suggestion function it is recommended to finish the classic design first and then create the RDLC report layout. The first reason is that the Create Layout Suggestion will suggest a layout from scratch and (ask to) overwrite the existing RDLC report layout. Any modifications that are made since the previous layout suggestion will have to be redone. Secondly, creating a report for the RoleTailored client sometimes requires changing the layout of the classic report: you might have to add additional controls to the classic report for the dataset to be complete. Creating the correct classic design will save some time when developing the RDLC report layout. Even if you do not plan to use the report in the Classic client, the minimum requirement is to have a complete dataset.
1-40
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports
RoleTailored Client-Only Reports As mentioned earlier, in Microsoft Dynamics NAV 2009 the two architectures coexist. RoleTailored client users will work with the RoleTailored client components, while Classic client users will continue to work with the classic components. In the standard application, practically all reports are available for both clients. However, this is not always the case. Some reports need to only be used by Classic client users, while other reports are only used by RoleTailored client users.
Classic Client-Only Reports In Microsoft Dynamics NAV 2009 it is still possible to create a classic report without an RDLC report layout. The presence of an RDLC report layout is not mandatory for the object to function correctly in the Classic client. Classic client users can run the report from the Object Designer or the menu (or from any other object using C/AL code). When a report is printed in the RoleTailored client, the presence of an RDLC report layout is checked first. If an RDLC report layout is present, it will be run in the RoleTailored client. If there is no RDLC report layout defined for the report, the RoleTailored client will try to print the classic report. To do this, it will try to locate the Classic client on the same computer. If the Classic client is found, it will be started in the background and used to print the classic report. If the Classic client is not installed on the same machine, nothing happens.
RoleTailored Client-Only Reports Although a classic report does not require an RDLC layout, it is impossible to create a RoleTailored client report without a classic layout. The first reason is that the RDLC report layout is stored inside the classic report object. The second reason is that the RDLC report layout does not contain any data query information. The dataset that is available in the Visual Studio Report Designer is created based on the classic design of the report. This means that you always have to create a classic layout that contains at least all the dataset elements that are needed in the RDLC report layout: fields, captions, format strings but also variables that are used on the request page. Data elements that are not included in the dataset cannot be used in the Visual Studio IDE. Meaning: you cannot add the customer's e-mail address to the RoleTailored client version of the customer list if the e-mail address is not present (visible or hidden) in the classic design of the report. Every time you open the RDLC layout in design mode, Microsoft Dynamics NAV will rebuild the dataset.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-41
Report Design in Microsoft Dynamics® NAV 2009 Once there is a correct dataset, you can build the desired layout using the toolbox, the dataset elements and expressions that are available in the Visual Studio IDE. Remember that there can be some differences between the Classic and the RDLC report layout. If you design a classic report: •
With a request page and without an RDLC layout, the RoleTailored client will try to print the classic version of the report.
•
Without a request page and with an RDLC layout, the RoleTailored client will use the RDLC report layout. It will try to propose a request page for each data item in the report. In case a DataItemTableView is defined for a data item, no tab will be presented in the request page. In case the classic report contains a request form, no tab will be created in the request page.
•
With a request page and with an RDLC report layout, it will use the RDLC report layout and the corresponding request page.
Summary This chapter explained the new architecture of Microsoft Dynamics NAV 2009 and the Visual Studio integrated development environment. It also looked at the differences between the Classic Report Designer and the Visual Studio Report Designer in relation to report creation, report execution, dataset generation, sorting and filtering data. Additionally the chapter also discussed some of the most frequently used properties and functions.
1-42
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports
Test Your Knowledge Test your knowledge with the following questions: 1. What is true about reports for the RoleTailored client? (Select all that apply) ( ) They must be created using the Visual Studio Report Designer. ( ) They can be printed in colors. ( ) They support only three sections. ( ) They can be created using the Report Wizard. 2. Which sections of the Classic client are not supported "as such" by the Visual Studio Report Designer? ( ) Header ( ) TransHeader ( ) Body ( ) Footer 3. Which report elements in the Classic design of a report are not automatically converted to or added as a DataSet field in Visual Studio? ( ) Currency Format strings for textboxes showing decimal values ( ) Textbox controls in TransHeader sections ( ) Label controls in any section ( ) Invisible textbox controls in Body sections 4. Which property can be set on a textbox to influence the name of the corresponding element in the dataset? ( ) DataSetName ( ) DataSetFieldName ( ) DataSetSourceExpr ( ) DataSetID 5. What does RDLC stand for? ( ) Compiled Report Definition Language ( ) Report Definition Language Control ( ) Client-side Report Definition Language ( ) Compact Report Definition Language
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-43
Report Design in Microsoft Dynamics® NAV 2009 6. Which possibilities for exporting reports are available in the RoleTailored client? (Select all that apply) ( ) XML ( ) PDF ( ) Microsoft Office Excel ( ) HTML 7. Which Data Item Properties are supported by the RoleTailored client? ( ) DataItemTableView ( ) DataItemLink ( ) NewPagePerRecord ( ) TotalFields 8. Under which circumstances is it possible to run a classic report on a computer running the RoleTailored client? ( ) The report must have an RDLC layout. The Classic client must be installed on the same machine. A request options page is mandatory. ( ) The report must have an RDLC layout. The Classic client must not be installed on the same machine. A request options page is optional. ( ) The report must not have an RDLC layout. The Classic client must be installed on the same machine. A request options page is optional. ( ) The report must not have an RDLC layout. The Classic client must not be installed on the same machine. A request options form is mandatory.
1-44
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports
Lab 1.1 - Creating a Table Report The purpose of this lab is to create a RoleTailored client report with a table layout from scratch. You will learn how to add formatting to specific fields, and will add grouping and totaling. In the next chapters, you will add some additional functionalities to the report. Scenario Your company has just implemented Microsoft Dynamics NAV 2009 and some additional reports need to be created. Throughout the labs, you will be assigned the role of Mort, a customization developer in the IT department. Mort is mainly responsible for fixing problems and implementing features and customizations in the internal IT applications. Kevin, the Sales Manager, has asked for an overview of the customer sales and profit (in local currency) by salesperson. The list needs to contain totals by salesperson, by country/region code, by customer and by document type. The list also needs to contain a grand total for all salespersons. The classic report is not finished yet. Only a draft version of the object exists, containing the correct data model and two sections. Your task is to build the report for the RoleTailored client, from scratch.
Challenge Yourself! Build a report showing: •
The total sales (LCY) and total profit (LCY) by document type, by customer no., by country/region code and by salesperson.
•
The subtotals for each group.
•
The grand total for all salespersons.
Dates and totals in the report must be formatted as defined in Microsoft Dynamics NAV.
Need a Little Help? 1. 2. 3. 4. 5. 6. 7.
Import the object in Microsoft Dynamics NAV. Open the object in Visual Studio. Add a Table control. Add Extra Columns to the Table. Add Dataset Elements to the Table. Add Currency Formatting. Add Date Formatting.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-45
Report Design in Microsoft Dynamics® NAV 2009 8. Add Grouping. 9. Add Subtotals. 10. Add Grand Totals.
Step by Step To create the report, the following steps need to be executed:
Import the Object To import the object in the demonstration database, use the following procedure: 1. 2. 3. 4. 5. 6. 7. 8. 9.
Open the Microsoft Dynamics NAV 2009 demonstration database. Open the CRONUS International Ltd. demonstration company Select Tools, Object Designer to open the Object Designer.. Select File, Import. Browse to the report R123456700.fob. Click OK to start the import. In the dialog box, choose to open the Import Worksheet window. In the Action column, verify that the action is set to Create. . Click OK to import the object in the database.
Open the Object in Visual Studio The first thing to do is to start the Visual Studio development environment to create the RDLC report layout. 1. In the Object Designer, open report 123456700, Sales by Salesperson - L1.1 in design mode. 2. Select View, Layout to open Microsoft Visual Studio. Visual Studio will open and show a blank Report Layout.
Add a Table to the Report Next, add some controls from the toolbox window to the report layout window. The Toolbox window is normally displayed on the left side of the Visual Studio IDE. If not, it can be made visible by pressing Ctrl+W, X. 1. In the Toolbox window, click the Table control. 2. Click in the Body section to add a table to the report. (You can also drag the Table control to the Body section). The report now contains a table with three rows (a header, detail and footer row) and three columns.
1-46
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports Add Columns to the Table The following steps show how to add additional columns to the table: 1. Select any cell in the table. Now a grey bar is displayed above each column: the column handle. The column handle can be used to select and/or resize a column. 2. Right-click on the column handle above the third column and select "Insert column to the right." A new column will be added to the table. The new column will have the same width as the selected column. 3. Repeat steps 1 and 2 three times. As a result the table will have three rows and seven columns.
Add Dataset Elements to the Table The dataset is generated based on the layout of the Classic report. It contains elements for the textboxes and labels in the Classic design. In addition, if the textboxes in the Classic design contain decimal values, the dataset will also contain format elements. These format elements can be used to give the same formatting in the RoleTailored as in the Classic client. The names of the dataset elements are created automatically. If you want to change the name of an element in the dataset, go to the Classic report design, find the corresponding control and change its DataSetFieldName property. When the DataSetFieldName for a textbox is changed, the DataSetFieldName of the corresponding format element is also changed. The following steps show how to add dataset elements to the table. 1. In the Website Data Sources window, select an item from the dataset. For example, select Customer__Salesperson_Code_. 2. Drag the selected element to a cell in the detail row of the table. In this case drag it to the first column in the Detail row. 3. Select the Customer__Country_Region_Code_ and drag it to the second column on the Detail row. 4. Select the Cust__Ledger_Entry__Customer_No__ and drag it to the third column on the Detail row. 5. Select the Cust__Ledger_Entry__Document_Type_ and drag it to the fourth column on the Detail row. 6. Select the Cust__Ledger_Entry__Posting_Date_ and drag it to the fifth column on the Detail row. 7. Select the Cust__Ledger_Entry__Sales__LCY__ and drag it to the sixth column on the Detail row. 8. Select the Cust__Ledger_Entry__Profit__LCY__ and drag it to the seventh column on the Detail row.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-47
Report Design in Microsoft Dynamics® NAV 2009 When you add a dataset element to the detail row, the corresponding Microsoft Dynamics NAV field caption element is added to the header row. In runtime, the caption element is automatically filled with the corresponding multilanguage caption. If you change the caption in the header row, the multilanguage functionality is lost. Close Visual Studio. You will be redirected to the Report Designer. Press Esc to leave the Report Designer. The following dialog box will be displayed:
FIGURE 1.11 MICROSOFT DYNAMICS NAV DIALOG BOX
Click Yes to load the RDLC layout in the report object. (If you select No, all changes made in the previous steps will be discarded, and the previous RDLC layout will be retained.) Press ESC again to leave the Report Designer. Click Yes to save the object.
Run the Report To check the layout of the report, run the report. 1. Select Start, Run. 2. In the Run window, enter the following command: DynamicsNAV:////runreport?report=123456700
1-48
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 3. Click OK. The RoleTailored client will be started and the request page of the report will be displayed. 4. Click the Preview button to run the report. The result will look something like this:
FIGURE 1.12 SALES REPORT PREVIEW
Add Currency Formatting to the Report In the Print Preview notice that some of the fields that show amounts (decimal values) are not formatted correctly: some have decimals, some do not have any decimals. If the report is run in the Classic mode, all amounts are formatted in the same way as defined in the G/L Setup window. To keep the same formatting in the RoleTailored client, you will need to change the formatting of the Sales (LCY) and Profit (LCY) fields. 1. Open report 123456700 in Visual Studio. 2. Select the Sales (LCY) field in the detail row. 3. Right-click the cell and select Properties.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-49
Report Design in Microsoft Dynamics® NAV 2009 4. Select the Format tab. On this tab, there are two options to define a format: by using a format, or by using an expression. If a format is being used, you can either select a standard format, or build your own custom format. However, you want to use the same formatting that is defined in the G/L Setup window. From previous steps, you know that the dataset also contains special formatting elements for decimal fields. These elements can only be selected using an expression. 5. Click the [Fx] button. The Expression window is displayed.
FIGURE 1.13 THE EXPRESSION WINDOW
6. Double-click the Cust__Ledger_Entry__Sales__LCY__Format element in the Fields (DataSet_Result) category. 7. Click OK to close the Expression window. 8. Repeat steps 2 to 7 to format the Profit (LCY) field using the Cust__Ledger_Entry__Profit__LCY__Format element. 9. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it.
1-50
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports The result will look similar to this:
FIGURE 1.14 SALES REPORT PREVIEW
Decimal and Thousand Separators By default, the decimal separator is "." while the thousand separator is ",". Both separators are not defined hardcoded. In fact, they depend on the language of the report. The language can be defined using the Language property of the report. As with the decimal formatting, you can use either a specific value (that applies for all users in all cases) or use an expression to make it user-dependent. 1. Open the report in Visual Studio. 2. In the Properties window, make sure Report is selected in the dropdown list. 3. Select the Language property. Note that the default value is set to "English (United States)," which explains the current decimal and thousand separator. 4. Click the drop-down list and select the first option in the list <Expression...>. The Expression window is displayed. 5. Replace the text "English (United States)" with the "=" sign. 6. Double-click the Language element in the Globals category. 7. Click OK to close the Expression window. 8. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-51
Report Design in Microsoft Dynamics® NAV 2009 The result will look similar to this:
FIGURE 1.15 SALES REPORT WITH SEPERATORS PREVIEW
Add Date Formatting to the Report In the Print Preview notice that the dates in the report are still displayed as a Date Time field. You will need to change the formatting of the Posting Date field. The following steps show how to add date formatting: 1. Open the report in the Report Designer. 2. Click View, Sections. 3. Right-click the textbox containing the Posting Date field and select Properties. 4. In the Properties window, set the SourceExpr property to: FORMAT("Posting Date", 0, '-<Month,2>-') 5. Right-click the label containing the caption for the Posting Date field and select Properties. 6. In the Caption property, enter Posting Date. 7. Close the Section Designer. 8. Save and compile the classic report in the Report Designer. Run the RoleTailored client report. Notice that all posting dates are formatted as defined in the classic report.
1-52
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports If it is preferred not to define a format in the Classic client, you can define the date format in Visual Studio. Suppose you want to have the date formatted as MM-DD-YYYY. 1. Open the report in the Report Designer. 2. Click View, Sections. 3. Right-click the textbox containing the Posting Date field and select Properties. 4. In the Properties window, set the SourceExpr property to Posting Date (Remove the format instruction entered earlier.). 5. Open the report in Visual Studio. 6. On the detail row, right-click the textbox containing the Posting Date field and select Properties. 7. In the Textbox Properties window, click the Format tab. 8. In the Format code field, click the [...] button. 9. In the Choose Format window, select the Custom option. 10. In the textbox, enter MM-dd-yyyy. 11. Click OK to close the Choose Format window. The specified date format will be copied to the Format code field in the Textbox Properties window. 12. Click OK to close the Textbox Properties window. 13. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it. The dates are now formatted according to the specified formula. Date formats specified in the classic design will overrule any format defined in Visual Studio.
Add Grouping to a Report The following steps show how to add a grouping to the table: 1. 2. 3. 4.
Open the object in the RDLC design mode. Select any cell in the table. The column and row handles appear. Select the detail row by clicking the row handle. Right-click the row handle for the detail row and select Insert group. 5. On the General tab, in the Group on listbox, select the =Fields!Customer__Salesperson_Code_.Value element. 6. On the Sorting tab, in the Sort on listbox, select the =Fields!Customer__Salesperson_Code_.Value element (to have the records sorted by Salesperson Code). 7. Click OK to close the Grouping and Sorting Properties window. Notice that two new rows are added to the table: a group header row (right above the detail row) and a group footer row (right below the detail row).
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-53
Report Design in Microsoft Dynamics® NAV 2009 8. Select the first cell on the detail row. 9. Drag it to the cell immediately above it in the group header row. Add a new grouping for the Country/Region Code field. 1. Select the detail row by clicking the row handle. 2. Right-click the row handle for the detail row and select Insert group. 3. On the General tab, in the Group on listbox, select the =Fields!Customer__Country_Region_Code_.Value element. 4. In the Parent group field, select the Fields!Customer__Salesperson_Code_.Value element. This indicates that the current group is a child of another group. 5. On the Sorting tab, in the Sort on listbox, define the sorting for the current group and select =Fields!Customer__Country_Region_Code_.Value. 6. Click OK to close the Grouping and Sorting Properties window. Notice that two new rows are added to the table: a group header row (right above the detail row) and a group footer row (right below the detail row). 7. Select the second cell on the detail row. 8. Drag it to the cell immediately above it in the group header row. Add a new grouping for the Customer No. field. 1. Select the detail row by clicking the row handle. 2. Right-click the row handle for the detail row and select Insert group. 3. On the General tab, in the Group on listbox, select the =Fields!Cust__Ledger_Entry__Customer_No__.Value element. 4. In the Parent group field, select the Fields!Customer__Country_Region_Code_.Value element. 5. On the Sorting tab, in the Sort on listbox, define the sorting for the current group and select =Fields!Cust__Ledger_Entry__Customer_No__.Value. 6. Click OK to close the Grouping and Sorting Properties window. 7. Select the third cell on the detail row. 8. Drag it to the cell immediately above it in the group header row. Add a new grouping for the Document Type field. 1. Select the detail row by clicking the row handle. 2. Right-click the row handle for the detail row and select Insert group. 3. On the General tab, in the Group on listbox, select the =Fields!Cust__Ledger_Entry__Document_Type_.Value element.
1-54
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 4. In the Parent group field, select the Fields!Cust__Ledger_Entry__Customer_No__.Value element. 5. On the Sorting tab, in the Sort on listbox, define the sorting for the current group and select =Fields!Cust__Ledger_Entry__Document_Type__.Value. 6. Click OK to close the Grouping and Sorting Properties window. 7. Select the fourth cell on the detail row. 8. Drag it to the cell immediately above it in the group header row. 9. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it. The result will look similar to this:
FIGURE 1.16 SALES REPORT WITH DATE FORMATTING PREVIEW
Add Subtotals to a Report The following steps show how to add totaling to a report: 1. Open the object in RDLC design mode. 2. Select the Cust__Ledger_Entry__Sales__LCY__ element and drag it to the sixth column on the group footer row for the Country/Region Code group. Notice that Visual Studio will automatically add the Sum function to the data element. 3. Specify the correct format for the subtotal. 4. Select the Cust__Ledger_Entry__Profit__LCY__ element and drag it to the seventh column on the group footer row for the Country/Region Code group.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-55
Report Design in Microsoft Dynamics® NAV 2009 5. Specify the correct format for the subtotal. 6. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it. The result will look similar to this:
FIGURE 1.17 SALES REPORT WITH SUBTOTALS PREVIEW
Add Grand Totals to a Report The following steps show how to add grand totals to a report: 1. Open the object in the RDLC design mode. 2. Select the Cust__Ledger_Entry__Sales__LCY__ element and drag it to the sixth column on the table footer row. Notice that Visual Studio will automatically add the Sum function to the data element. 3. Specify the correct format for the grandtotal. 4. Select the Cust__Ledger_Entry__Profit__LCY__ element and drag it to the seventh column on the table footer row. 5. Specify the correct format for the grandtotal. 6. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it.
1-56
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports The result will look similar to this:
FIGURE 1.18 SALES REPORT WITH GRANDTOTALS PREVIEW
In steps 2 and 4, instead of selecting the fields in the dataset, it is possible to copy the cells from the Country/Region Code footer. By copying the cell, you copy both the value and the format (and other properties). In the next chapter you will further fine-tune the report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-57
Report Design in Microsoft Dynamics® NAV 2009
Lab 1.2 - Creating a Matrix Report The purpose of this lab is to create a RoleTailored client report with a matrix layout from scratch. You will learn how to add formatting to specific fields, and how to add grouping and totaling. The classic layout is available as a separate object on the training DVD, namely report R123456701.fob. Use this as a starting point. In the next chapters, you will add some additional functionalities to the report. Scenario Ellen is the Warehouse Manager, and one of her tasks is to optimize the entire warehouse. She ensures that item inventory levels are accurate and that periodic physical inventory counts occur. Ellen asks Mort to build a report showing the item inventory by location.
Challenge Yourself! Build a matrix report for report 123456701 showing the total Inventory by Location Code. Location Codes need to be printed as bold white text on a dark Blue background. Item Numbers need to be printed as black text on an Orange background.
Need a Little Help? 1. 2. 3. 4. 5. 6. 7. 8.
Import the object in Microsoft Dynamics NAV. Open the report in Visual Studio. Add a matrix control to the report. Change the position of the matrix. Add dataset elements for the Items to the matrix. Add dataset elements for the Locations to the matrix. Add totals to the report. Add formatting to the matrix control.
Step by Step The following steps need to be executed:
Import the Object To import the object in the demonstration database, use the following procedure: 1. Open the Microsoft Dynamics NAV 2009 demonstration database. 2. Open the CRONUS International Ltd. demonstration company 3. Select Tools, Object Designer to open the Object Designer..
1-58
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 4. 5. 6. 7. 8. 9.
Select File, Import. Browse to the report R123456701.fob on the training DVD. Click OK to start the import. In the dialog box, choose to open the Import Worksheet window. In the Action column, verify that the action is set to Create. . Click OK to import the object in the database.
Open the Object in Visual Studio The first thing to do is to start the Visual Studio development environment to create the RDLC report layout of the report. 1. In the Object Designer, open report 123456701, Item Maxtrix - L1.2 in design mode. 2. Select View, Layout to open Microsoft Visual Studio. Visual Studio will open and show a blank Report Layout.
Add a Matrix Control to the Report Next, add some controls from the toolbox window to the report layout window. The Toolbox window is normally displayed on the left side of the Visual Studio IDE. If not, it can be made visible by pressing Ctrl+W, X. 1. In the toolbox window, click the Matrix control. 2. Click in the Body section to add a matrix to the report. (You can also drag the Matrix control to the Body section). The report now contains a matrix with two rows and two columns.
Change the Position of the Matrix Control When you place a matrix control on the body section, it might not have the correct position. The position of the control can be changed either by dragging the control to the correct position or by changing the control properties. 1. Select any cell in the matrix. 2. Press Esc. The size handles (white blocks) will appear. 3. Use the size handles to drag the control to the desired position (by preference in the top left corner). Eventually you can resize the control. As an alternative for step 3, you can change the position of the control by changing the properties of the matrix.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-59
Report Design in Microsoft Dynamics® NAV 2009 In the Properties window, select the matrix1 control. The properties for the matrix will be displayed (and the matrix control will be selected.)
FIGURE 1.19 REPORT LAYOUT WINDOW
Add Dataset Elements for the Items to the Matrix In the dataset, select the Item__No__ element and drag it to the first cell on the second row of the matrix control.
Add Dataset Elements for the Locations to the Matrix In the dataset, select the Item_Ledger_Entry__Location_Code_ element and drag it to the second cell on the first row of the matrix control.
Add Totals to the Matrix In the dataset, select the Item_Ledger_Entry_Quantity element and drag it to the second cell on the second row of the matrix control. The Sum() operator is automatically added.
Add Formatting to the Matrix 1. Select the textbox containing the Item No. field. 2. In the Properties window, set the BackgroundColor property to Orange. 3. Select the textbox containing the Location Code field. 4. In the Properties window, set the BackgroundColor property to DarkBlue.
1-60
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 5. 6. 7. 8.
In the Properties window, set the Color property to White. In the Properties window, set the FontWeight property to Bold. Select the textbox containing the Quantity field. In the Properties window, in the BorderStyle property collection, set the Left, Right, Top, Bottom and Default properties to Solid. 9. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it. The result will look similar to this:
FIGURE 1.20 MATRIX REPORT PREVIEW
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-61
Report Design in Microsoft Dynamics® NAV 2009
Lab 1.3 - Adding a Chart The purpose of this lab is to add a chart to an RDLC report layout. The chart will be based on variables from the dataset (instead of fields). Finally, you will finetune the chart by adding some basic formatting. Scenario As a Project Manager, Prakash is using report 1009, Job Actual to Budget to compare the budgeted and the realized amounts of the different jobs. To have an overall view that includes all jobs, Prakash asks Mort to present the figures in the report by means of a chart. To avoid destroying the original report, Mort will start from report 123456709, which is a copy of the standard report 1009.
Challenge Yourself! Add a column chart to report 123456709. The chart needs to display: •
The total budgeted cost price (LightCoral).
•
The total realized cost price (Red).
•
The total budgeted sales price (LightGreen).
•
The the total realized sales price (ForestGreen).
Need a Little Help? 1. 2. 3. 4.
Import report 123456709. Add a column chart to the report. Add dataset elements to the chart. Add formatting to the chart.
Step by Step In this lab, you will perform the following tasks:
1-62
•
Import report 123456709, Job Actual to Budget - Chart.
•
Add a column chart to the report.
•
Add dataset elements to the chart.
•
Add formatting to the chart
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports Import Report 123456709 To import the object in the demonstration database, use the following procedure: 1. 2. 3. 4. 5. 6. 7. 8. 9.
Open the Microsoft Dynamics NAV 2009 demonstration database. Open the CRONUS International Ltd. demonstration company Select Tools, Object Designer to open the Object Designer.. Select File, Import. Browse to the report R123456709.fob on the training DVD. Click OK to start the import. In the dialog box, choose to open the Import Worksheet window. In the Action column, verify that the action is set to Create. . Click OK to import the object in the database.
Check Report 123456709 Before starting to design the report, it is recommended to check the existing classic layout of the report. 1. Select report 123456709 in the Object Designer. 2. Click the Design button to open the Report Designer. The logical layout of the report is displayed. Notice that the structure of the report is more complex: it uses several instances of the Integer data item. Look at the sections of the report. 3. Select View, Sections to open the Section Designer. First, notice there are several sections. Secondly, notice that the details and the totals of the report are printed in body sections that belong to the FirstBuffer, SecondBuffer, JobTaskTotal and JobTotal data items. Look back at the logical design, notice that these sections correspond to the Integer table. Look at the textboxes in the body section of the JobTotal data item, notice that the totals are not displayed using fields but using variables. In this case it is the JobTotalAmt[] variable which is defined as an array of decimals. 4. Press Esc to close the Section Designer.
Design Report 123456709 Now start designing the RDLC report layout. 1. In the Object Designer, open report 123456709, Job Actual to Budget - Chart in design mode. 2. Select View, Layout to open Microsoft Visual Studio. Since the report is a copy from the standard report 1009, it already has an RDLC layout.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-63
Report Design in Microsoft Dynamics® NAV 2009 Add a Chart to the Report The following list of steps shows how to add a chart to the report: 1. Select the Body section by clicking on the right grey bar or by selecting the Body option in the Properties window. 2. Change the height of the Body section by changing its Height property (in the Size property collection). Set the Height property to 18cm. 3. Use the vertical scrollbar to visualize the bottom end of the Body section. 4. In the Toolbox window, select the Chart control. 5. Click the Body section to insert a Chart control. 6. Click the Website Data Sources window to display the dataset. 7. In the dataset, select Job_No_ and drag it to the Category area of the chart.
8. 9. 10. 11. 12.
Next, add the fields containing the job totals to the Data area. However, in this case, the totals are displayed using variables. In the dataset, you must select the variables that are used in the sections to display the job totals and drag them to the Data area of the Chart. Select JobTotalAmt_4_ and drag it to the Data area. Select JobTotalAmt_5_ and drag it to the Data area. Select JobTotalAmt_7_ and drag it to the Data area. Select JobTotalAmt_8_ and drag it to the Data area. Change the size of the chart by changing its properties: set the Height property to 7cm and set the Width property to 18cm
Add Formatting to the Chart Now it is time to add some formatting to the report. Add a chart title, change the names in the legend, change the default colors of the columns and add some effects.
The Chart Legend When viewing the chart it shows that the legend contains the names of the variables. Change this to more clear names: 1. 2. 3. 4.
Right-click the chart control and select Properties. On the Data tab, in the Values list box, select Job Total Amt 4. Click the Edit button. In the Edit Chart Value window, set the Name field to Budgeted Cost Price. 5. Click OK to return to the Chart Properties window. 6. In the Values list box, select Job Total Amt 5. 7. Click the Edit button.
1-64
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports 8. In the Edit Chart Value window, set the Name field to Realized Cost Price. 9. Click OK to return to the Chart Properties window. 10. In the Values list box, select Job Total Amt 7. 11. Click the Edit button. 12. In the Edit Chart Value window, set the Name field to Budgeted Sales Price. 13. Click OK to return to the Chart Properties window. 14. In the Values list box, select Job Total Amt 8. 15. Click the Edit button. 16. In the Edit Chart Value window, set the Name field to Realized Sales Price. 17. Click OK to return to the Chart Properties window. 18. Click OK to close the Chart Properties window.
Add a Chart Title The following steps show how to add a title to the chart. 1. Right-click the chart control and select Properties. 2. On the General tab, in the Title field, enter Job - Actual vs. Budget. 3. Click the Style button next to the Title field, and format the title to Verdana, 12 pt, Bold and Red. 4. Click OK to close the Style Properties window.
Change the Column Colors The following steps show how to change the default colors of the columns. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
Right-click the chart control and select Properties. On the Data tab, in the Values list box, select Budgeted Cost Price. Click the Edit button. In the Edit Chart Value window, on the Appearance tab, click the Series Style button. In the Style Properties window, on the Border & Line tab, click the Style button next to the Color field and select Light Coral. Click the Fill tab. Click the Style button next to the Color field and select Light Coral. Click OK to close the Style Properties window and return to the Edit Chart Value window. Click OK to close the Edit Chart Value window. On the Data tab, in the Values list box, select Realized Cost Price.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-65
Report Design in Microsoft Dynamics® NAV 2009 11. Repeat steps 3 to 10 for the Realized Cost Price value. Set the Border and Fill Color to Red. 12. On the Data tab, in the Values list box, select Budgeted Sales Price. 13. Repeat steps 3 to 10 for the Budgeted Sales Price value. Set the Border and Fill Color to LightGreen. 14. On the Data tab, in the Values list box, select Realized Sales Price. 15. Repeat steps 3 to 10 for the Realized Sales Price value. Set the Border and Fill Color to Forest Green. 16. Click OK to close the Chart Properties window.
Other Chart Format Options Now, add labels to clarify the elements shown on the X and Y axis of the chart. 1. Right-click the chart control and select Properties. 2. On the X Axis tab, set the Title field to Job. You can use the Style button next to the Title field to format the title. 3. On the Y Axis tab; set the Title field to Total Amt. in LCY. You can use the Style button next to the Title field to format the title. 4. On the Legend tab, you can choose to show or hide the legend, and to change the layout and the position of the legend. 5. Click OK to close the Chart Properties window.
Add Visual Effects to the Chart Lastly, add some 3-D effect to the chart. 1. Right-click the chart control and select Properties. 2. On the 3-D Effects tab, check the Display chart with the visual 3-D effect field. By checking the field, the other options on the tab will be enabled. 3. Change the Horizontal rotation to 5°. 4. Change the Wall Thickness to 30%. 5. Change the Vertical rotation to 0*. 6. Click OK to close the Chart Properties window. 7. Now that the chart is finished, exit Visual Studio, import the new RDLC layout in the object, save the object and run it.
1-66
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports The result will look similar to this:
FIGURE 1.21 JOB ACTUAL TO BUDGET REPORT PREVIEW
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-67
Report Design in Microsoft Dynamics® NAV 2009
Quick Interaction: Lessons Learned Take a moment and write down three Key Points you have learned from this chapter 1.
2.
3.
1-68
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 1: Creating Reports
Solutions Test Your Knowledge 1. What is true about reports for the RoleTailored client? (Select all that apply) ( ) They must be created using the Visual Studio Report Designer. (√) They can be printed in colors. (√) They support only three sections. ( ) They can be created using the Report Wizard. 2. Which sections of the Classic client are not supported "as such" by the Visual Studio Report Designer? ( ) Header (√) TransHeader ( ) Body ( ) Footer 3. Which report elements in the Classic design of a report are not automatically converted to or added as a DataSet field in Visual Studio? ( ) Currency Format strings for textboxes showing decimal values (√) Textbox controls in TransHeader sections ( ) Label controls in any section ( ) Invisible textbox controls in Body sections 4. Which property can be set on a textbox to influence the name of the corresponding element in the dataset? ( ) DataSetName (•) DataSetFieldName ( ) DataSetSourceExpr ( ) DataSetID 5. What does RDLC stand for? ( ) Compiled Report Definition Language ( ) Report Definition Language Control (•) Client-side Report Definition Language ( ) Compact Report Definition Language
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
1-69
Report Design in Microsoft Dynamics® NAV 2009 6. Which possibilities for exporting reports are available in the RoleTailored client? (Select all that apply) ( ) XML (√) PDF (√) Microsoft Office Excel ( ) HTML 7. Which Data Item Properties are supported by the RoleTailored client? (√) DataItemTableView (√) DataItemLink ( ) NewPagePerRecord ( ) TotalFields 8. Under which circumstances is it possible to run a classic report on a computer running the RoleTailored client? ( ) The report must have an RDLC layout. The Classic client must be installed on the same machine. A request options page is mandatory. ( ) The report must have an RDLC layout. The Classic client must not be installed on the same machine. A request options page is optional. (•) The report must not have an RDLC layout. The Classic client must be installed on the same machine. A request options page is optional. ( ) The report must not have an RDLC layout. The Classic client must not be installed on the same machine. A request options form is mandatory.
1-70
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features
CHAPTER 2: INTERACTIVE FEATURES Objectives The objectives are: •
Learn when to use headers and footers and how to add or delete a header or footer section.
•
To understand the difference between Print Preview and Print Layout.
•
Describe the visibility options for the RoleTailored client and how to use them.
•
Understand interactive sorting and know how to implement it.
•
Understand the way document maps work and how to add them to a report
Introduction In the previous chapter the new architecture of Microsoft Dynamics® NAV 2009 was introduced and the anatomy of a report was explained in detail. You learned how to create a basic report for the RoleTailored client, but now it is time to dive a little deeper into the possibilities that the world of Reporting Services has to offer. In environments that support interactivity reports can include a variety of features that provide interactivity to users. Users can influence the appearance of a report and the data it contains by typing or selecting a value for a filter before running the report. A user can show or hide items in a report and click links that go to other reports, Web pages and RoleTailored client pages. Reporting Services also provides a document map, which acts like a table of contents. A user can click items in the document map to jump to areas within a report. Formatting the items in your report makes the report look more attractive and enhances its readability. You can format the text boxes and individual items within text boxes, the images, the expressions, and the data while in design mode. You can design a report so that different styles are applied to report items or properties based on the data in the report. You can build conditional expressions using any feature supported by expressions, including built-in report and aggregate functions, built-in collections, and custom code. In this chapter we will explain some of the interactive features Reporting Services has to offer for the reports that will be running on the RoleTailored client.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-1
Report Design in Microsoft Dynamics® NAV 2009 Objectives In the previous chapter you were introduced in the new reporting solution. You created a basic report and basically used the dataset to implement currency and date formatting. In this chapter you will discover the interactive features from the new solution. You will learn to work with different types of headers and footers, how to define interactive sorting, how to apply visibility options, how to use pictures and how to add extra navigation features such as document map.
Working with Headers and Footers Both in the Classic client and in the RoleTailored client you can use headers and footers in reports. But there is a big difference here between the two clients. The Classic client has more types of headers and footers than the RoleTailored client. The purpose and functionality of headers and footers in the Dynamics NAV Report Designer and in the Visual Studio Report Designer are also completely different. Page headers and footers can contain static content, but they are more commonly used to display varying content like page numbers or information about the contents of a page. It is important to have a good understanding of the purpose, capabilities and limitations of headers and footers, in both environments.
For the Classic Client In the Classic Client, you can add multiple sections to a report. To add a section in the Section Designer, you select Edit, and then click New. In the Insert New Section window, you select a data item, a section type and a section position. There are different kinds of sections available in the Classic client:
2-2
Section
Purpose
Body
Prints for each iteration of the data item loop. When there is an indented data item, the complete loop for this data item begins after the body section of the higher level data item has been printed.
Header
Prints before a data item loop begins. If the PrintOnEveryPage property of the section is set to Yes, the header is also printed on each new page.
Footer
Prints after the loop has finished. If the PrintOnEveryPage property of the section is set to Yes, the footer is also printed on each new page. If the PlaceInBottom property of the section is set to Yes, the footer section is printed at the bottom of the page, even if the data item loop ends in the middle of a page.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Section
Purpose
GroupHeader
When a new group starts this section is printed.
GroupFooter
When a new group ends this section is printed.
TransHeader
If a page break occurs during a data item loop, the TransHeader is printed at the top of the new page. This section is printed after any header section of the data item.
TransFooter
If a page break occurs during a data item loop, the TransFooter is printed before the page break This section is printed before any footer section of the data item.
In a report that is going to be printed, each data item has one or more sections. A section can be thought of as a block of information that should be printed. The complete report is composed of a number of sections. Some sections are printed only once, for example, headers. Other sections are printed for each record retrieved from the database. The information printed in the sections is displayed using controls. The available controls are: •
Text boxes – for printing the result of the evaluation of any valid C/AL expression, such as the contents of a table field (also used for complex calculations).
•
Labels – for printing static text such as a caption for a column of data.
•
Shapes, images and picture boxes – for printing graphical elements (lines, circles) and bitmap pictures.
After you have defined one or more data items, you can design the visual layout of the report in Section Designer. You can use the Field Menu to select fields and place them in the sections as controls. You can think of each section as one or more lines on the paper that the report will eventually be printed on. A header section is printed only once, while a body section is typically printed several times as each loop of the report is iterated. You can control whether the header should be printed every time a page break occurs while the body sections of the same data item are being printed. You can edit properties and triggers for each section by opening the Properties window or the C/AL Editor, respectively, while the section is selected. The controls you place in the sections have a subset of the properties that controls have on forms, not all the properties are relevant for a report. You can see a list of the properties in the Properties window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-3
Report Design in Microsoft Dynamics® NAV 2009 Example:
FIGURE 2.1 THE REPORT HEADER IN REPORT 206
As you can see a report can contain multiple headers and footers for one data item.
For the RoleTailored Client If the classic client supports 7 section types, in the RoleTailored Client there are only three section types: a Header, a Body and a Footer section. No additional sections can be added. When you open Visual Studio Report Designer, all three sections will normally be displayed. Visual Studio Report Designer supports less section types than Section Designer. Example: TransHeader and TransFooter sections are not supported in the RoleTailored client. When printing a report, Microsoft Dynamics NAV 2009 will first print the header section, then the body section and finally the footer section. You can have only one header, one body and one footer in a report. The next paragraphs explain which classic sections are supported in the RoleTailored client and how to add, design or delete these sections.
2-4
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Page Header / Footer The page header is the first section that will be printed when a report is run. Typically a header contains some general information, such as: •
the report title
•
the user who printed the report
•
date and time information
•
page number and or number of pages
•
company logo
The page header will normally be printed at the beginning of the report. However you can have it printed on every page by setting the page header's properties. The Page Header and Page Footer sections correspond to the Header and Footer section of the Classic client, the only difference being that in the RoleTailored client they are only defined once. Note: if you add paging information to a header, it might not always be correct when you run the report in preview mode, especially if the report has a long body section. If you print the report to a printer, the information will be correct. For more information about this, see the section Print Preview and Print Layout.
Design a Header/Footer Section If no header or footer has been defined yet for the report in Visual Studio, only the body section will appear. Headers and footers can be designed in the same way as body sections. To add a control to a header section, grab the control in the Visual Studio Toolbox and drag it to the header section. Alternatively, select the control in the Toolbox, then click the Header section to insert the control. You cannot add data region controls (table, matrix, chart, list and subreport) to a header or footer. You can use the Header or Footer properties to add borders, background images, or colors, or to adjust the width of the header. To access the Header or Footer properties, right-click the corresponding section and select Properties.
Delete a Page Header or Page Footer Headers and footers can be removed easily using the same toggle items that you use for adding a header or footer. By removing a header or footer section, you delete it from the report. Any controls that you previously added to the section will be destroyed. If you subsequently add the header or footer section again, the controls will not reappear. To delete an existing Page Header or Page Footer section, select Report, then choose respectively Page Header or Page Footer in the menu
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-5
Report Design in Microsoft Dynamics® NAV 2009 Alternatively, you can right-click the Page Header or Page Footer section, then choose Delete from the menu. Finally, you can also delete a page header section by right-clicking either the report selection handle or the design surface and choose Page Header or Page Footer from the menu.
FIGURE 2.2 DELET A PAGE HEADER OR FOOTER FROM THE DESIGN SURFACE
A default Page Header, Footer and Body Section for All Reports If you want to design a basic company layout for all reports, you can change the standard Visual Studio solution template that is used as a base for all new reports. To do this, open the solution that is installed together with the classic client under C:\Program Files\Microsoft Dynamics NAV\60\Classic\ReportLayout2008. This is the default location for the solution, but if required you can change this. Change the design to fit your needs (even include embedded images) and save the files. The modified solution is used as a template for all new RoleTailored client reports that are created from scratch in the Visual Studio Report Designer. However, if you use the Create Layout Suggestion function, the template files will not be used. If you work with Visual Studio 2005, you should change the solution that is found under C:\Program Files\Microsoft Dynamics NAV\60\Classic\ReportLayout2005. This is the default location for the solution, but if required you can change this. Remember to copy the modified solution to all clients that will be used to design reports.
2-6
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Data Fields in Page Header and Page Footer From chapter 1, you know that Visual Studio Report Designer has a serious limitation: data fields cannot be added to a Page Header or Footer. Although in design mode you will be able to add a textbox to a Page Header, drag a field from the dataset to it, and even import the RDLC data in the report, you will not be able to save the report in Report Designer. Instead an error message will be displayed: This looks like a very serious limitation. However, there is a scenario to get around this. The scenario can be found in various standard reports: 1. Add the data elements to the body section, and make them invisible by using the visible property of their textbox. (The control should refer to the value of a field in the Fields collection.) 2. Add a new textbox control to the Page Header. 3. Right-click the textbox in the Page Header and select Expression. The Expression window will appear. 4. After the = sign, enter the following text: ReportItems! The system will automatically display a list of all available textboxes in the ReportItems collection. 5. From the ReportItems collection, select the (invisible) textbox from the body section containing the data element to display in the header. 6. Enter a "." Now a list with properties is displayed. Elements in the ReportItems collection have only one property: Value. 7. Click the Value property to add it to the expression. The entire expression should look like this. =ReportItems!.Value (where TableFilter represents the name of the textbox control in the body section.) 8. Click OK to close the Expression window. This scenario can be used to have filter expressions displayed in a page header. Using the GETFILTERS instruction, you can put the filter criteria in a text variable. The text variable must then be added to the visual design in Section Designer, to make it appear in the dataset. Next, you can add it to the body section of the RDLC layout, as a separate textbox or as a table column. Finally, you can use the ReportItems collection to retrieve the contents of the invisible textbox in the Header section. If you change invisible controls to a section, it is recommended to change the color of the controls, in order to distinguish them from the visible report controls. When using this scenario, it is recommended to add the variable as an invisible column to a table in the body section. As tables might span several pages, the variable (and its contents) will travel along and will always be available.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-7
Report Design in Microsoft Dynamics® NAV 2009 If you place the filter string in a separate textbox (instead of a table column), the reference to the textbox and its value might be lost as soon as the report spans more than one page. (The textbox will normally be printed only once.) However, you can have the text box travel along with the table and have it repeated on every page: 1. Right-click the textbox control and select Properties. 2. Check the Repeat report item with data region on every page. 3. In the Data Region field, select the data region that the textbox control is connected with. The text box will now be repeated on all pages spanned by the table. The ReportItems collection contains the text boxes within the report. Items within the ReportItems collection have only one property: Value. The value for a ReportItems item can be used to display or calculate data from another field in the report.
Demonstration: Add a Page Header or Footer Mort has to add a report header to his reports. In order to do that, he adds a Page Header section to the report. 1. Open the report in Visual Studio. 2. To add a Page Header section, select Report, Page Header in the menu 3. To add a Page Footer section, select Report, Page Footer in the menu. As an alternative solution, you can use the following procedure to add the Page Header or Page Footer section: 1. Right-click either the report selection handle or the report design surface 2. Select Page Header and/or Page Footer in the menu.
2-8
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features A header and/or footer will now be added to the report. In both menus, Page Header and Page Footer are toggle items; they can be used both for adding and deleting the section.
FIGURE 2.3 AN ROLETAILORED CLIENT REPORT WITH A PAGE HEADER AND PAGE FOOTER
Group Header / Footer In the Classic client, the GroupHeader and GroupFooter sections are used for printing grouping information and subtotals. Both sections were respectively printed at the start and at the end of each group of records. While the GroupHeader section was used to display the grouping criteria, the GroupFooter was used for printing subtotals. Using these sections (in combination with the DataItemTableView, TotalFields and GroupTotalFields properties) is a requirement for having correct totals and groups in the classic client. In the RoleTailored client, group headers and group footers are not displayed using separate sections. Instead they can be added as additional rows or columns to data region controls (rows for a table, and columns in a matrix control).
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-9
Report Design in Microsoft Dynamics® NAV 2009 After adding a group header and footer, two new rows have been added to the table (one immediately above the detail row, and on immediately below). These are the Group Header and the Group Footer row. On the row handle, you see the group row icon containing the group level. This is very convenient if you want to group data on multiple levels. For example, if you want to print a list of customers, grouped by salesperson and then by country/region. On the detail row, you will have the details of your customer (no., name, phone no.). The first group you add will be a grouping on salesperson code. The second group you insert will be a grouping on country/region code.
Grouping on Multiple Levels It is possible to group data on several levels. Take the example of the customer list, grouped by country/region by salesperson. This can be done by inserting multiple groups. Please note that if you add multiple group headers, the new header will be created on the lowest possible level. First, you select the detail row and insert a group to group on Country/Region Code. Secondly, you select the detail row again and insert a second group to group on Salesperson Code. Note that the second group will be created inside the first group. In order to have the correct grouping, make sure to start with the highest grouping level. If you need to insert a new grouping between two other grouping levels (e.g. customers by country by continent by salesperson), then be sure to select the highest grouping level (the salesperson group) before inserting the new continent group.
Design a Group Header or Group Footer To add data to a group header or footer, select an element in the dataset and drag it to a cell in the group header or footer. (You can obtain the same result by setting a value for the Value property of the header or footer cell.) You can also take values from cells in other rows (for example the detail row). Note that if you add a decimal value to the group header or footer, Visual Studio Report Designer will automatically add the Sum operator to the field value. As a consequence, the subtotal for the corresponding group will be displayed. This way, you can group data on any field and have subtotals calculated, without having to define any keys (with SumIndexFields) nor to set sorting, grouping and totaling properties in Microsoft Dynamics NAV. This is in fact a huge benefit compared to the Classic Report Designer.
Delete a Group Header or Group Footer Follow the instructions below, to delete a group header and the corresponding footer: 1. Right-click the row handle of the group header or footer to delete 2. Choose Delete Group. In this case, both the group header and its footer will be removed.
2-10
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features If you want to delete a group footer without the corresponding group header, proceed as follows: 1. Right-click the row handle of the correct group level. 2. Select Edit Group. 3. In the Grouping and Sorting Properties window, uncheck the Include group header or Include group footer options to remove the header and/or the footer. 4. Click OK to apply the changes. As an alternative solution, you can manage the groups (add, edit and delete) in the Table Properties window. 1. Select any cell in the table, then press Esc. (If you want, you can obtain the same result by selecting the table control in the Properties window.) 2. Right-click the grey dotted table border and select Properties. 3. Click the Groups tab. Here you see a list of all groupings that have been defined for the table. 4. Use the buttons in the window to add new groups, delete and edit existing groups or to change the order of the groups. 5. Click OK to apply the changes and close the Table Properties window.
Demonstration: Add a Group Header or Footer To group the data and display totals in the report, Mort will use group headers and group footers. The following example shows how to add a group header to a table control in the RoleTailored client. 1. Select a detail row in a table. 2. Right-click the row handle and select Insert group. The Grouping and Sorting Properties window will be displayed. 3. On the General tab, in the Group on list box, select the fields or values on which you want to group the data in the table. 4. Use the checkboxes in the bottom of the window to control the behavior of the group header. When you add a group header, a group footer will be inserted at the same time. If you uncheck the Include group footer field, the group footer will not be created. 5. Click OK to close the Grouping and Sorting Properties window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-11
Report Design in Microsoft Dynamics® NAV 2009 Table Header / Footer In Classic client, the body section of a data item is printed for every record in a data item. In RoleTailored client, there is only one body section, which is printed once. In order for a report to show multiple records from a table, a repeating data control such as a table is needed. A table is a repeating data region control. Unlike a line or a rectangle, a table control (and more in particular the detail row) is used to loop through the records of a table and display data. In addition; the detail row is designed (normally) only once and then repeated for every record in the recordset. You can add multiple tables to the body section. A table can have three types of rows: Row Type
Description
Table Header
The table header is printed once for each table. This is a typical place to put captions. If you drag an item containing text from your data set into a header, the environment automatically adds “First” to it. “First” means that it will show the first value in the data set, as opposed to looping through each record in the data set. Tables can have multiple table headers.
Table Details
The detail row is used to display data from the dataset. It can be compared to the body section of the classic Section Designer. Tables can have multiple detail rows.
Table Footer
The table footer is printed once for each table. It is a typical place to insert subtotals or grand totals. If you drag an item containing a numerical value from your dataset into a footer, the environment automatically adds “Sum” to it, and the report will print the total from the report. Tables can have multiple footers.
By combining table headers and footers with group header and footers, you can print any total you want, even if you don't have any corresponding table keys in Microsoft Dynamics NAV. When you add a table header and footer, two new rows are added to the table (one immediately above the detail row, and on immediately below). These are the table header and the table footer row. In case group headers and or footers have been defined for the table, the table header will be inserted above all group headers and the table footer will appear after all group footers. On the row handle, you see the table header or table footer row icon.
2-12
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Design a Table Header or Table Footer To add data to a group header or footer, select an element in the dataset and drag it to a cell in the table header or footer. (You can obtain the same result by setting a value for the Value property of the header or footer cell.) You can also take values from cells in other rows. Note that if you add a decimal value to the header or footer, Visual Studio Report Designer will automatically add the Sum operator to the field value. As a consequence, the grand total for the table will be displayed. This way, you can have totals calculated, without having to define any keys (with SumIndexFields) nor to set sorting, grouping and totaling properties in Microsoft Dynamics NAV. This is in fact a huge benefit compared to the classic report design.
Delete a Table Header or Table Footer Follow the instructions below, to delete a table header and the corresponding footer: 1. Right-click the row handle of any row in the table. 2. Click the toggle items Table Header and/or Table Footer In this case, all table headers and footers will be removed. If you want to delete an individual header or footer row, proceed as follows: 1. Right-click the row handle of the correct table header or footer. 2. Select Delete Rows. Only the selected row will be deleted.
Demonstration: Add a Table Header or Footer Mort will add a table header and a table footer row to display the field captions. The following example shows how to add a table header to a table control. 1. Select a detail row in a table. 2. Right-click the row handle and select Table Header or Table Footer.
Repeat Headers and Footers on New Pages In Classic client, you can have headers and footers repeated on every page by setting the PrintOnEveryPage property on the corresponding sections. In RoleTailored client, you can do this by setting the RepeatOnNewPage property on each of the individual header and footer rows.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-13
Report Design in Microsoft Dynamics® NAV 2009 As an alternative solution, you can define this for all headers or footers at the same time in the Table Properties window. 1. Select any cell in the table, then press Esc. (If you want, you can obtain the same result by selecting the table control in the Properties window.) 2. Right-click the grey dotted table border and select Properties. 3. Set the RepeatHeaderOnNewPage and RepeatFooterOnNewPage properties. 4. Click OK to apply the changes and close the Table Properties window. Changing the Table Properties window will cause the properties of the underlying table and the individual table rows to change. Setting the RepeatOnNewPage property on an individual table header row will cause the table property RepeatHeaderOnNewPage to get the same value. Note: the Repeat Group Header option is a function that will only work in the report viewer. It will not apply when exporting the report to Excel and or PDF.
Freezing the Header Rows in Preview Mode If you want the header rows to remain visible when scrolling in a report, you can also define this in the Table Properties window. Note that when you export the report to Excel, the worksheet window in Excel will be split in multiple resizable panes. The Page Header section will be put in one pane (and remain visible) while the body section will be put in another.
Colors in Headers and Footers Unlike reports for the classic client, reports for the RoleTailored client can be printed in color. Although you can define colors for controls in the Section Designer, colors will not be printed when the report is run. The only way to print colors in the Classic Client is to use Image or PictureBox controls.
Using Colors in Headers and Footers In order to fine-tune the layout and to get a beter view on the contents of the report, you can work with colors. Colors allow to emphasize specific pieces of data and also to reflect the structure of the content. For example, you can have the Unit Price printed in blue and the Unit Cost in red. Or you can print a specific group header row (and the corresponding group footer) with a green background color, so you can easily distinguish the logical structure of the report (everything between the two green rows is a logical group.) You can define the colors for each individual control by setting the BackgroundColor and Color properties. The Color property defines the text color; the BackgroundColor property determines the background color of the control. By default the BackgroundColor property is set to Transparent and the Color is set to Black.
2-14
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features In Visual Studio Report Designer it is also possible to set the BackgroundColor and Color properties for multiple controls at the same time. If you select multiple individual controls or an entire table row or column, you can change the background and text color for all these controls by setting both properties. This is not possible in Classic Report Designer; Beside the BackgroundColor and Color properties, there are a number of other properties (TextAlign, CanGrow, CanShrink) and property collections (Font, Padding, BorderColor, BorderStyle, BorderWidth...) that can be defined for multiple controls at the same time (provided that the properties are common to all selected controls).
Adding Texts to Headers and Footers As you work with headers and footers and subtotals on different levels, it might be interesting to print extra "labels" explaining the data printed in the report. For example, next to each subtotal you can print a text like "Total for Customer 10000", "Total for Country AT". Or you can add the name of the customer to a separate cell in the "Customer No." group header. The additional texts can be a fixed text, an element from the dataset, or a combination of both. To print a text in a specific cell, you simply select the cell and change its Value property. It is recommended to use the Expression window, as it allows you both to enter text and to select variables, functions... from a list. You should bear in mind that the width of the cell containing the text depends on the size of the column in the table detail row. If you want to include longer texts in a header or footer row, you might have to merge the cells from the row before inserting the text. To merge cells, select the necessary cells, right-click any of the selected cells and choose Merge Cells. If you want to split the cells, right-click the merged cell and select Split Cell. To enter a custom text in the merged cell, proceed as follows: 1. Select the merged cell. 2. Select its Value property in the Properties window. 3. From the dropdown list, select <Expression...>. The Expression window will appear. 4. In the listbox the current cell value - if any - is displayed. If the cell is empty, only the "=" sign will be displayed. Make sure not to delete the "=" sign. It indicates that the cell value is an expression and not a fixed text. If you remove the "=" sign, all text that you enter in the expression window will be displayed as plain text.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-15
Report Design in Microsoft Dynamics® NAV 2009 5. In the listbox, you can now compose an expression consisting of fixed texts and/or variables, functions, dataset elements, etc. Fixed text should be placed between double quotes. To use a dataset element, function, variable..., select the element in the corresponding category and double-click it. If the text consists of multiple parts, you can use the ampersand (&) to concatenate the parts. 6. Click OK to close the Expression window. The expression will be copied to the Value property. Finally, you can change the alignment of the texts by setting the individual cell properties. In the same way, you might want to have the customer name printed next to the customer number. To do this, merge the necessary cells (if necessary) then drag the Customer Name from the dataset to the right cell in the group header.
Using Pictures in a Report Pictures can be displayed using the Image control. In the RoleTailored client, you can work with three sources of pictures: •
embedded pictures
•
external pictures
•
database pictures from a table in Microsoft Dynamics NAV
Embedded Pictures Embedded pictures are pictures that are stored in the report itself. To import a picture in the report, select Report, Embedded Images. Click the New Image button, select an image file, and click OK.
External Pictures External pictures are not stored in the report or in a database. Instead they come from a public external location, like for example the Internet. External pictures are supported in Microsoft Dynamics NAV 2009 SP1. To use external pictures, the EnableExternalImages property must be set to True. Using external pictures is not recommended for security reasons.
Database Pictures from Microsoft Dynamics NAV In the report you can also work with pictures that come from the NAV database, for example to print an item catalog including the item pictures, or even to print the company logo that is stored in the Company Information table. Database pictures can be added to Header, Body and Footer sections. However, adding database pictures to headers and footers requires using code and expressions.
2-16
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Image Properties When working with pictures, there are three important properties: Source: This property indicates the source of the picture. Supported options in Microsoft Dynamics NAV 2009 are Embedded and Database. It is also possible to use an expression to define the picture source. MIME Type: This property contains the MIME Type of the picture; MIME is an Internet standard for describing the contents of a file. The property is used in HTML to render the picture in the correct way. Examples are image/bmp, image/gif, image/jpeg, application/pdf, application/msword... If you want to use pictures from a database table, you will need to set this property to image/bmp (as pictures are stored as bitmaps in Dynamics NAV). Value: This property contains the name of the picture that is displayed in the image control. The property can contain a picture name (for embedded pictures) or a field from the dataset (for database pictures). MIMEType applies only if the Source property is set to Database. If the Source property is set to External or Embedded, the value of MIMEType is ignored.
Adding Pictures To add a picture to a report, you first have to add a control to the report that can contain a picture. In the Section Designer, there were two controls that can be used to display images. In the Visual Studio Report Designer, there is only one control: the image control.
Adding an Embedded Picture To add an embedded picture, select Report, and then select Embedded Images from the menu bar. In the Embedded Images window, you see a list of all pictures that have been stored in the report. Here you can delete existing pictures and/or add new ones. To delete an existing image from the report, select the image and click the Delete button. Embedding pictures can be done at any time, even without having any image controls in the report. As a next step, you will add an image control and link the control to an embedded image. After you have added the Image control, you can use the properties of the Image control to link the control to an image. Afterwards, the selected image will be shown in the Image control. By default, the Image control will be resized to the image's proper size. If you resize the Image control, you will see that the Sizing property is changed from AutoSize to Fit. Note that the MIME Type property is set automatically. It contains the value of the MIME Type property as it has been defined in the Embedded Images window. You can change the MIME Type in the Properties window; however the changes will be overwritten.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-17
Report Design in Microsoft Dynamics® NAV 2009 Embedded pictures can be used in header, body and footer sections.
Adding an External Picture The procedure for adding an external picture to the report is almost identical to the procedure for adding embedded images. You use the Image control to display the picture then set the properties for the image control. You must set the Source property to External and the Value property to the exact external location of the picture. However, to enable the use of external pictures, you must set the report property EnableExternalImages to TRUE. (The default value for the property is FALSE.) If you don't set this property and use an external picture in the report, an error message will be displayed. External pictures can be used in header, body and footer sections. Remember that external pictures are supported in Microsoft Dynamics NAV 2009 SP1. Furthermore, the use of external images is not recommended for security reasons.
Adding a Picture From a Table in Microsoft Dynamics NAV Like with an embedded or external image, you can use the Image control to display pictures that are stored in a table in Microsoft Dynamics NAV. Typical examples are the Company Information and the Item table. The procedure for using database pictures depends on the section it will be added to.
Adding a Database Picture to the Body The procedure is the same as for an embedded image: you insert an Image control and link it to a picture using the control properties. Instead of linking to an embedded image, you will link to an element in the dataset. Prerequisite of course is that the Picture element is part of the dataset, which implies that the picture is also part of the classic design. If you want to print a "loose" picture (such as a company logo), you can work with a single Image control. If you want to print a picture as part of a record, you will have to work with a repeating container (such as a table control), and insert an image control in a table cell.
2-18
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Adding a Database Picture to the Header or the Footer Suppose you want to add the company logo to a report. From chapter 1, you know that the Visual Studio Report Designer has a serious limitation: data fields cannot be added to a Page Header or Footer. As an alternative, you can convert the database picture into an embedded picture. You could try to include it in the Body section, but the body section will not function as a real header. However, there is a way to use database pictures in a Header section, but it requires using custom code and expressions. This will be demonstrated in Chapter 3.
Other Image properties After you inserted the Image control, you can use the other properties to further fine-tune the layout and the position of the image control.
Background Images You can use an image as a background image in the body of the report or in a rectangle, text box, list, matrix, or table. A background image has the same properties as an image. You can also specify how the image is repeated to fill the background of the item. If you define a background image for the report body, but not the page header or footer, HTML reports will automatically use the same background image in all three regions of the report. If you do not want to use the background image in the header or footer, you must explicitly define a different image for those regions. If you do not want any image to appear in those regions, you can create and assign a small transparent image to the header or footer to create the effect of having no image at all. To add a background image, do the following: 1. Open the client report definition (.rdlc) file in graphical design mode. 2. Select the report item to which you want to add a background image. Note: Background images apply only to rectangle, text box, table, matrix, list, or report body items.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-19
Report Design in Microsoft Dynamics® NAV 2009 3. In the Properties window, expand BackgroundImage, and then do the following: For Source, select Embedded, External or Database. For Value, type or select an expression that evaluates to the source of the image. If the Source property is set to Embedded, the expression must evaluate to the name of an image that is embedded in the report. If the Source property is set to Database, the expression must evaluate to a field that contains binary image data. If the Source property is set to External, remember to set the EnableExternalImages property to True. For MIMEType, select the appropriate MIME type for the image. 4. For BackgroundRepeat, select Repeat, NoRepeat, RepeatX, or RepeatY.
Demonstration: Adding an Image Control To add an image control to the report, follow the list of steps below: 1. Open the report in Visual Studio. 2. In the Toolbox window, select the Image control. 3. Click the Header, Body or Footer section to insert the image control.
Demonstration: Adding an Embedded Picture to a Report To add an embedded picture to the report, proceed as follows: 1. Click New Image. 2. In the Import Image dialog box, select the image to embed in the report. You can select the following image file types: *.bmp, *.gif, *.png, *.jpg and *.jpe. 3. Click Open to import the file. Now the newly embedded image will be added to the Embedded Images window. The name and MIME type of the image are imported automatically into the Name and MIME Type columns. They can be changed if you want. 4. Click OK to close the window and save the newly embedded image. Click Cancel to cancel the embedding.
2-20
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Demonstration: Display an Embedded Picture in a Report 1. Select the image control. 2. In the Properties window, set the Source property to Embedded. As a consequence, all embedded images will be available in the Value property. 3. In the Properties window, click the Value property. Select the image from the list.
Demonstration: Display a Database Picture in the Body Section 1. Select the image control. 2. In the Properties window, set the Source property to Database. As a consequence, all fields from the dataset will be available in the Value property. 3. In the Properties window, select the corresponding field from the dataset.
Print Preview and Print Layout Preview mode is a new feature in Microsoft Dynamics NAV 2009. This section explains the difference between the two modes: Print Preview and Print Layout.
How Does It Work? When you run a report in the RoleTailored Client, a request page appears. In this page you can have three options: •
Cancel the report
•
Print the report
•
Preview the report.
Cancel will close the popup and you return to the RoleTailored Client. Print will send the report to the printer, but Preview will open the Report Viewer. Besides these options in the request page you also have the possibility to apply filters to the report or fill in options in the options tab, if there were any options defined for the report. The Report Viewer allows you to preview the report before sending it to the printer, or saving it as a PDF or Excel file.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-21
Report Design in Microsoft Dynamics® NAV 2009 At the top of the Report Viewer window there is a toolbar. In this toolbar you have a number of buttons:
FIGURE 2.4 THE REPORT VIEWER TOOLBAR
One of these buttons is the Print button, which will allow you to send the report to the printer. At the right side of the Print button, there is a button called Print Layout. If you click this button, the report will be regenerated in Print Layout mode. In this mode you can see exactly how the report will be printed on paper (in contradiction to the Print Preview mode, where you cannot see the width of the page and the page breaks.) By clicking the Print Layout button again, you can switch back to Print Preview mode.
Working with Visibility Options The new reporting solution in Microsoft Dynamics NAV 2009 takes advantage of the more advanced reporting functionalities of Microsoft SQL Server Reporting Services. This lesson describes the interactive features (such as visibility options, interactive sorting and document maps) that can be added to reports for the RoleTailored client. More information regarding browser support can be found on http://msdn.microsoft.com/en-us/library/ms251673.aspx
2-22
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features For the Classic Client In the Classic client, it is possible to influence the content of a report by using a request form. A typical scenario would be: •
You use the request form to offer a number of printing options to the user.
•
You design a number of sections to cover the necessary printing layouts.
•
In the OnPreSection trigger you use the CurrReport.SHOWOUTPUT() statement together with the variables from the request form to print or hide a section based on the user's preference.
Although this functionality involves a lot of design work to create the different sections (to cover all combinations of user options), it can often cover the user's needs. However, it has one disadvantage: sometimes the user has to spend a lot of time browsing and scrolling through the report, especially in large reports with grouping on different levels. But here you are faced with a dilemma: the report contains information that you don't want to see, but that can not be omitted for some reason (like totaling). Basically you have the option whether or not to include some data. If you don't include it, you don't have the information you need. If you include it, you might get overwhelmed by a huge amount of data. Moreover, the report can become difficult to analyze when the information of a specific data item is spread over several pages.
For the RoleTailored Client The RoleTailored client offers a very nice visibility feature that gives the user the possibility of dynamically expanding and collapsing groups of data. This allows the user to gradually step into the content of a report, making the report complete and easier to analyze. Let's look at report 123456700, Sales by Salesperson - L1.1. The report contains an overview of the total sales and profit amount, broken down by salesperson, country/region code, customer number and document type. Suppose you want to have a look at the sales amount realized by John Roberts, and particularly in Germany. You would like to see the details of Germany, and at the same time, you want to see the correct totals for all countries/regions. If you print the report in Classic design, you see the details of all customers and countries. You cannot filter the data item, because you would lose the details for the other countries, resulting in wrong totals. Once the information is printed, there is no way to collapse specific sections. The same comment applies to the RoleTailored client layout of the report. You see all details, even the details that you don't want to see at this time. In the next paragraphs you will see how to work with visibility options.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-23
Report Design in Microsoft Dynamics® NAV 2009 The Visibility Feature The Visibility feature is a toggle feature you can use to dynamically show or hide data regions using the Expand/Collapse technique. When you add the visibility feature to a specific data region, the data region will get a small + icon. If you click it, the region will be expanded, and at the same time, the icon will change from a + to a -. If you click it again, the region will be collapsed and the icon will change back into a +. Visibility options defined for a group header will also apply to the corresponding group footer (and vice versa).
Implement the Toggle Visibility functionality The visibility feature is typically used in data region controls, to influence the visibility of grouped data (table rows, matrix columns). Although it can be defined for each cell, you normally define it by table row. Often you will define visibility options for all levels except the highest data level. Visibility options are often defined in a cascading scenario.
Visibility and Totaling So far you have added visibility options for the different groupings. Still you need to expand the different groups and look at the group footers in order to know the subtotals for each group. To avoid this, you can have the totals displayed in the group header row, so you see the subtotals without having to expand the individual groups. (In this case, the group footers become obsolete in a way.) To add the totals to the group header, select the fields in the dataset and drag them to the correct cell in the group header. (You can also copy or move the fields from the footer row.) When you add a numerical field to a header or footer, the Sum() function will be added automatically. As a result, the header will contain the same information as the footer. You can now disable the individual footers, as described in the section Delete a Group Header or Group Footer section.
Demonstration: Adding Toggle Visibility Options In report 123456700, you would define visibility options for the Country/Region Code, Customer No. and Document Type group headers and the table details row (showing the individual customer ledger entries). The following list of steps shows how to define visibility options for a table row: 1. Right-click the row handle for the table row you want to add visibility options to. In this case, select the Country/Region Code group header. 2. Select Edit Group.
2-24
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 3. On the Visibility tab, select an initial visibility state for the data level. Default state is Visible (which means that the data region will be expanded). If you select Hidden, the data region will appear collapsed. In this case, select Hidden. 4. Check the Visibility can be toggled by another report item option. 5. In the Report Item field, select the control that can influence the visibility of the selected table row. In this case, select Customer__Salesperson_Code_.value. 6. Click OK to close the Grouping and Sorting Properties window. Now you have defined the visibility for one level. You can repeat the procedure above to define it for the remaining levels. If you run the report afterwards, the result will look similar to this:
FIGURE 2.5 ROLETAILORED CLIENT REPORT WITH VISIBILITY OPTIONS
You notice that the report shows only the two salespersons. The details for the Country/Region Code grouping (and all underlying groupings) are hidden. If you click the Expand/Collapse icon, the details of the next level are shown; if you click the button again, the details are hidden again. You can have the initial visibility state determined by an expression. This is often used to influence the visibility of individual controls. Using expressions will be described in Chapter 3.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-25
Report Design in Microsoft Dynamics® NAV 2009
Interactive Sorting Sorting data in the Microsoft Dynamics NAV Classic client is strictly related to keys. The different sorting orders for data must be defined as keys. After you have defined a key, you can use it in tables, forms, reports... to sort data in the desired order. In reports, you can either let the user define the sorting order, or you can predefine the sorting order (using the DataItemTableView property on data item level). In any way, the sorting order is defined before the report is printed. If a different sorting order is required, you must run the report again. The RoleTailored client supports interactive sorting. This means that you can add sort buttons to the data columns which allow you to change the sorting of the data after the report is run. When you view the report, columns that support interactive sorting have arrow icons that change to indicate the sort order. The first time you click an interactive sort button, items are sorted in ascending order. Subsequent clicks toggle the sort order between ascending and descending order. Working with interactive sorting allows you to support multiple user requirements while minimizing development time.
What is Interactive Sorting Interactive sort can be defined on multiple columns. In reports without grouping, the data will be sorted according to the selected column and the selected sort order (ascending or descending). In this case interactive sorting will affect the whole data region, from top to bottom and from left to right. To some extent, you can say that interactive sorting here equals interactive grouping: data will be sorted and also grouped differently (as each record will be a group on its own). In reports with grouping, interactive sorting will depend on grouping. The interactive sort functionality is limited to a specific group of data. By changing the sorting of a specific group, you will affect the sorting of the data in the current group (and underlying groups), but it should not affect the sorting and will not affect the grouping that have been defined on a higher level. In case of reports with grouping, it is important to define the correct sorting scope. For each column the user can select the sort order. For example; you can have the first column sorted in ascending order, the second in descending order, the third in ascending order again... Visibility options might have a side-effect on interactive sorting: when you change the sorting on a column, the data for the current group will be refreshed, taking into account the Initial visibility settings. When combining interactive sorting and visibility options, you have to remember to first select the right sorting order for the different columns before expanding the data groups.
2-26
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Demonstration: Adding Interactive Sorting - No Grouping Mort needs to add interactive sorting to report 101, Customer - List, so that customers can be sorted interactively on Salesperson Code. The following list of steps shows how to activate interactive sorting for a column in a report without grouping. 1. Open report 101 in Visual Studio Report Designer. 2. Select the header cell for the column you want to add interactive sort to. 3. Right-click the cell and select Properties to open the Textbox Properties window. 4. On the Interactive Sort tab, check Add an interactive sort action to this textbox. 5. In the Sort expression field, select the name of the field to sort on.
FIGURE 2.6 INTERACTIVE SORTING ON SALESPERSON CODE
6. Click OK to close the Textbox Properties window. Exit Visual Studio, save and import the RDLC changes, save and compile the report in the Report Designer and run the report.
Demonstration: Adding Interactive Sorting - Grouping (Group Header Field) After he introduced interactive sorting in some reports, Mort receives similar requests for all kind of reports. Michael asks him to change the sorting in report 113, Customer/Item Sales, so that he can sort cusomer No. In addition, Michael would like to sort the data by Item No. and by Item Description.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-27
Report Design in Microsoft Dynamics® NAV 2009 Mort will first define the interactive sorting on the Customer No. field, which is a group header field. The following list of steps shows how to activate interactive sorting for a group header field in a report with grouping: 1. Open report 113 in Visual Studio Report Designer. 2. Select the header cell for the column you want to add interactive sort to. In this case, interactive sort must be added to the Customer No. column. Note that the Customer No. column does not contain a caption. You can either include one or leave it blank. 3. Right-click the cell and select Properties to open the Textbox Properties window. 4. On the Interactive Sort tab, check Add an interactive sort action to this textbox. 5. In the Sort expression field, select the name of the field to sort on. In this case, select =Fields!Customer__No__.Value. 6. In the Evaluate sort expression in this scope field, select the Choose data region or grouping option. 7. In the Choose data region or grouping field, select table1_group. This means that changing the sort order will only affect the selected group (and the underlying groups). It is important that you select the correct scope for each group).
FIGURE 2.7 INTERACTIVE SORT FOR A GROUP HEADER FIELD
8. Click OK to close the Textbox Properties window. Exit Visual Studio, save and import the RDLC changes, save and compile the report in Report Designer and run the report.
2-28
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Demonstration: Adding Interactive Sorting - Grouping (Detail Field) Now that interactive sort is added to the Customer No. field, Mort needs to add interactive sorting for the Item No. and Item Description fields. Both fields appear on the detail level of the The following list of steps shows how to activate interactive sorting for a detail column in a report with grouping: 1. Open the report in Visual Studio Report Designer. 2. Select the header cell for the column you want to add interactive sort to. In this case, you will add interactive sort to the Item No. field. . 3. Right-click the cell and select Properties to open the Textbox Properties window. 4. On the Interactive Sort tab, check Add an interactive sort action to this textbox. 5. In the Sort expression field, select the name of the field to sort on. In this case, select =Fields!ValueEntryBuffer__Item_No__.Value. 6. In the Evaluate sort expression in this scope field, select the Detail Scope option. This means that changing the sort order will only affect the detail scope of the table.
FIGURE 2.8 INTERACTIVE SORT FOR A DETAIL ROW FIELD
7. Click OK to close the Textbox Properties window. 8. Select the header cell for the column you want to add interactive sort to. Next, you will add interactive sort to the Item Description field. . 9. Right-click the cell and select Properties to open the Textbox Properties window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-29
Report Design in Microsoft Dynamics® NAV 2009 10. On the Interactive Sort tab, check Add an interactive sort action to this textbox. 11. In the Sort expression field, select the name of the field to sort on. In this case, select =Fields!Item_Description.Value. 12. In the Evaluate sort expression in this scope field, again select the Detail Scope option. 13. Click OK to close the Textbox Properties window. Exit Visual Studio, save and import the RDLC changes, save and compile the report in the Report Designer and run the report.
Working with Document Maps In this lesson, you will learn how to improve the navigation of a report by working with a document map. You will learn how to define a name and map levels for the document map. In addition you will see what happens to the document map when exporting in different formats.
What is a Document Map A document map is a built-in feature of Microsoft SQL Server Reporting Services that allows the user to quickly navigate the contents of a report. The document map has a tree view structure. It appears as a separate side pane next to the report content, and functions as a table of contents: when you click an item in the document map, the report content at the right side will be refreshed. If you change the sorting of the report, the document map will be rebuilt to follow the sorting of the document. The document map is will be rendered differently depending on how you will export the report: •
PDF renders a document map as the Bookmarks pane. All items in the document map are listed one after the other down the pane. There is no hierarchy to the list of links.
•
Excel renders a document map as a named worksheet that includes a hierarchy of links. Report sections are rendered in separate worksheets that are included with the document map in the same workbook.
You can use a document map in a report to provide users with a way to navigate to certain areas of the report. When you view an Excel or PDF report, a document map appears along the side of the report. Clicking items in the document map refreshes the report and displays the area of the report that corresponds to the item in the document map. You can add multiple document maps to a report. If the report contains multiple data region controls, you can add a document map for each data region control.
2-30
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features In this case, it is recommended to specify a document map label for each data region control. Document maps provide a hierarchical overview of the information in the report. Often they contain entries for the different groups that have been defined.
Demonstration: Adding a Document Map The following list of steps shows how to create a document map. 1. Open report 123456700 in Visual Studio Report Designer. 2. Right-click the top left corner of the table that you want to create a document map for and select Properties to open the Table Properties window. 3. On the Groups tab, select the group that you want to include in the document map and click Edit. 4. In the Document map label field, select the field that you want to show in the document map. In this example, select Fields!Customer__Salesperson_Code_.Value. (You can select other fields than the one in the Group on field. For example, you can group the data on Customer No. and include the Customer Name in the document map. You can even combine multiple fields by entering an expression.) 5. Click OK to close the Grouping and Sorting Properties window. 6. Repeat steps 3 to 5 for each group level that you want to include in the document map. 7. On the Navigation tab, enter a name for the data region in the Document map label field. The name will allow you to identify the data region control in the document map. This is very convenient if the report contains multiple data region controls. 8. Click OK to close the Table Properties window. 9. Exit Visual Studio, save and import RDLC changes, save and compile the report in the Report Designer.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-31
Report Design in Microsoft Dynamics® NAV 2009 When you run the report in the RoleTailored Client, the result will look similar to this:
FIGURE 2.9 A REPORT WITH A DOCUMENT MAP
Notice the Expand button in the top left corner. Unfortunately this does not display anything in Microsoft Dynamics NAV 2009 RTM. This will be fixed in Service Pack 1.
The Document Map Settings The document map settings are defined in the Grouping and Sorting Properties window, which can also be accessed by right-clicking the row handle for each group header row then selecting Edit Group. If you define the document map settings in this way, you need to open the Table Properties window afterwards to specify a document map label for the table. Specifying a document map label for the table is not mandatory. However it is recommended to do this when the report contains multiple data region controls. If you don't specify any names for the different tables, all document map entries will be included sequentially. The document map will loose at least some of its added value. When you run the report in preview mode, you can click a button in the ReportViewer toolbar to enable or disable the document map.
2-32
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features What about reports without grouping? Even when no groups have been defined in the report, you can include a document map: 1. Right-click the row handle for the detail row and select Edit Group. 2. On the General tab, select the field that you want to add to the map in the Document map label field. 3. In the Group on field, select the field that you want to group the data on. This is typically the default sorting field. 4. Click OK to close the Details Grouping window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-33
Report Design in Microsoft Dynamics® NAV 2009
Lab 2.1 - Adding Visibility Options In this lab you will learn how to add interactive features to a report. Scenario In Lab 1.1 Mort finished the rough design of the Sales by Salesperson report. He added the necessary groups and also included subtotals and grand totals. However, Kevin has a few extra wishes. First of all, he would like to have the totals displayed on group level (with drilldown possibilities). In addition, he would like to see the Customer Name printed next to the Customer No. Finally, he asks Mort of it is possible to use different colors in the headers and footers, to ease report navigation. Mort adds the necessary visibility options and extra information to the report.
Challenge Yourself! Change the report so that: •
By default, only the salesperson codes are displayed.
•
By clicking the Salesperson Code, the Country/Region Code group will be expanded.
•
By clicking the Country/Region Code, the Customer No. group will be expanded.
•
By clicking the Customer No., the Document Type group will be expanded.
•
By clicking the Document Type, the Customer Ledger Entry details will be expanded.
•
Subtotals are displayed in Header rows.
•
Extra information labels such as "Total for XX" are displayed next to the totals.
•
The Headers and Footers have different background colors.
•
The Customer Name is displayed in the Customer Group Header.
Need a Little Help? Execute the following list of steps: 1. Add Visibility options for the Country/Region Code, Customer No., Document Type levels 2. Add Visibility Options for the Detail Row. 3. Have the Salesperson Group Totals Displayed in the Header 4. Have the Country/Region Code group totals displayed in the header 5. Have the Document Type Group Totals Displayed in the Header
2-34
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 6. 7. 8. 9.
Add an Information Label to the Customer No. Footer Row Add an Information Label to the Table Footer Row Change Background Colors of Headers and Footers Add the Customer Name to the Customer Group Header
Step by Step Add Visibility Options for the Country/Region Code, Customer No., Document Type Levels 1. Open the RDLC layout of report 123456700 in the Visual Studio Report Designer. 2. Right-click the top left corner of the table for and select Properties to open the Table Properties window. 3. On the Groups tab, select the table1_group2 and click Edit. 4. On the Visibility tab, in the Initial Visibility field, select Hidden. 5. Check the Visibility can be toggled by another report item field. 6. In the dropdown list, select Customer__Salesperson_Code_. 7. Click OK to close the Grouping and Sorting Properties window. 8. On the Groups tab, select the table1_group3 group and click Edit. 9. On the Visibility tab, in the Initial Visibility field, select Hidden. 10. Check the Visibility can be toggled by another report item field. 11. In the dropdown list, select Customer__Country_Region_Code_. 12. Click OK to close the Grouping and Sorting Properties window. 13. On the Groups tab, select the table1_group4 group and click Edit. 14. On the Visibility tab, in the Initial Visibility field, select Hidden. 15. Check the Visibility can be toggled by another report item field. 16. In the dropdown list, select Cust__Ledger_Entry__Customer_No__. 17. Click OK to close the Grouping and Sorting Properties window. 18. On the Groups tab, select the table1_group4 group and click Edit.
Add Visibility Options for the Detail Row 1. 2. 3. 4. 5.
Right-click the row handle for the table details row. Seleect Edit Group. On the Visibility tab, in the Initial visibility field, select Hidden. Check the Visibility can be toggled by another report item field. In the dropdown list, select Cust__Ledger_Entry__Document_Type_. 6. Click OK to close the Details Grouping window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-35
Report Design in Microsoft Dynamics® NAV 2009 Have the Salesperson Group Totals Displayed in the Header 1. Select the subtotal for the Sales LCY field in the Salesperson Code footer row. (This is the first grouping level.) 2. Drag it to the corresponding group header (same column). 3. Select the subtotal for the Profit LCY field in the Salesperson Code footer row. (This is the first grouping level.) 4. Drag it to the corresponding group header (same column). 5. Right-click the row handle for the Salesperson Code group footer. 6. Select Delete Rows. (The footer will be deleted.)
Have the Country/Region Code Group Totals Displayed in the Header 1. Select the subtotal for the Sales LCY field in the Country/Region Code footer row. (This is the second grouping level.) 2. Drag it to the corresponding group header (same column). 3. Select the subtotal for the Profit LCY field in the Country/Region Code footer row. (This is the second grouping level.) 4. Drag it to the corresponding group header (same column). 5. Right-click the row handle for the Country/Region Code group footer. 6. Select Delete Rows. (The footer will be deleted.)
Have the Document Type Group Totals Displayed in the Header 1. Select the subtotal for the Sales LCY field in the Document Type footer row. (This is the fourth grouping level.) 2. Drag it to the corresponding group header (same column). 3. Select the subtotal for the Profit LCY field in the Document Type footer row. (This is the fourth grouping level.) 4. Drag it to the corresponding group header (same column). 5. Right-click the row handle for the Document Type group footer. 6. Select Delete Rows. (The footer will be deleted.)
Add an Information Label to the Customer No. Footer Row 1. In the only group footer row, select the third, fourth and fifth cell. 2. Right-click any of the selected cells and select Merge Cells. 3. Right-click the new merged cell and select Expression.
2-36
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 4. In the Build an expression using Visual Basic language syntax, after the "=" sign, enter "Total for Customer ", followed by the "&" sign. (be sure to include the double quotes and add a space before and after the ampersand.) 5. In the Category list, select Fields (DataSet_Result). 6. In the Field list, double-click Cust__Ledger_Entry_Customer_No_.Value 7. Click OK to close the Expression window. 8. In the Properties window for the merged cell, set the TextAlign property to Right. 9. In the Properties window for the merged cell, set the FontWeight property (in the Font property collection) to Medium.
Add an Information Label to the Table Footer Row 1. 2. 3. 4.
In the table footer row, select the third, fourth and fifth cell. Right-click any of the selected cells and select Merge Cells. Right-click the new merged cell and select Expression. In the Build an expression using Visual Basic language syntax, after the "=" sign, enter "Total for all Salespersons" (be sure to include the double quotes). 5. Click OK to close the Expression window. 6. In the Properties window for the merged cell, set the TextAlign property to Right. 7. In the Properties window for the merged cell, set the FontWeight property (in the Font property collection) to Bold.
Change Background Colors of Headers and Footers 1. 2. 3. 4. 5. 6.
Click the row-handle for the first group header row. In the Properties window, set the BackgroundColor to LightCoral. Click the row-handle for the second group header row. In the Properties window, set the BackgroundColor to LightGreen. Click the row-handle for the third group header row. Press the Ctrl key, and keep it pressed down, while you click the row handle for the corresponding group footer row. (Now two rows have been selected.). 7. In the Properties window, set the BackgroundColor to LightSkyBlue. 8. Click the row-handle for the fourth group header row. 9. In the Properties window, set the BackgroundColor to Yellow.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-37
Report Design in Microsoft Dynamics® NAV 2009 Add the Customer Name to the Customer Group Header 1. In the (blue) Customer No. group header, select the fourth andf fifth cell. 2. Right-click the cells and select Merge Cells. 3. Select the Customer_Name field in the dataset. 4. Drag it to the newly merged cell.
2-38
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features
Lab 2.2 - Adding Interactive Sorting In this lab you will add Interactive Sorting for a number of fields. Scenario After implementing the Visibility options, Mort presents the new report to Kevin, who is really excited. He asks Mort to duplicate the report, but with different sortings. Mort decides to implement interactive sorting for a number of fields, so that Kevin can change the sorting of the data without having to run the report again.
Challenge Yourself! Add interactive sorting for the following fields: •
Salesperson Code
•
Country Region Code
•
Customer No.
•
Posting Date
•
Profit (LCY)
Need a Little Help? 1. 2. 3. 4. 5.
Add Interactive Sorting for the Salesperson Code Field. Add Interactive Sorting for the Country/Region Code Field. Add Interactive Sorting for the Customer No. Field. Add Interactive Sorting for the Posting Date Field. Add Interactive Sorting for the Profit (LCY) Field.
Step by Step Add Interactive Sorting for the Salesperson Code Field 1. Open report 123456700 in Visual Studio Report Designer. 2. Select the first cell in the table header row, the cell containing the caption for the Salesperson Code field. 3. Right-click the cell and select Properties. 4. On the Interactive sort tab, check the Add an interactive sort action to this textbox. 5. In the Sort expression field, select =Fields!Customer__Salesperson_Code_.Value 6. In the Evaluate Sort Expression in this scope field, select Choose data region or grouping.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-39
Report Design in Microsoft Dynamics® NAV 2009 7. In the Choose data region or grouping field, select table1_Group1. 8. Click OK to close the Textbox Properties window.
Add Interactive Sorting for the Country/Region Code Field 1. Open the report in Visual Studio Report Designer. 2. Select the second cell in the table header row, the cell containing the caption for the Country/Region Code field. 3. Right-click the cell and select Properties. 4. On the Interactive sort tab, check the Add an interactive sort action to this textbox. 5. In the Sort expression field, select =Fields!Customer__Country_Region_Code_.Value 6. In the Evaluate Sort Expression in this scope field, select Choose data region or grouping. 7. In the Choose data region or grouping field, select table1_Group2. 8. Click OK to close the Textbox Properties window.
Add Interactive Sorting for the Customer No. Field 1. Open the report in Visual Studio Report Designer. 2. Select the third cell in the table header row, the cell containing the caption for the Customer No. field. 3. Right-click the cell and select Properties. 4. On the Interactive sort tab, check the Add an interactive sort action to this textbox. 5. In the Sort expression field, select =Fields!Cust__Ledger_Entry_Customer_No_.Value 6. In the Evaluate Sort Expression in this scope field, select Choose data region or grouping. 7. In the Choose data region or grouping field, select table1_Group3. 8. Click OK to close the Textbox Properties window.
Add Interactive Sorting for the Posting Date Field 1. Open the report in Visual Studio Report Designer. 2. Select the fifth cell in the table header row, the cell containing the caption for the Posting Date field. 3. Right-click the cell and select Properties. 4. On the Interactive sort tab, check the Add an interactive sort action to this textbox. 5. In the Sort expression field, select =Fields!Cust__Ledger_Entry__Posting_Date_.Value
2-40
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 6. In the Evaluate Sort Expression in this scope field, select Detail Scope. 7. Click OK to close the Textbox Properties window.
Add Interactive Sorting for the Profit (LCY) Field 1. Open the report in Visual Studio Report Designer. 2. Select the last cell in the table header row, the cell containing the caption for the Profit LCY field. 3. Right-click the cell and select Properties. 4. On the Interactive sort tab, check the Add an interactive sort action to this textbox. 5. In the Sort expression field, select =Fields!Cust__Ledger_Entry__Profit__LCY__.Value. 6. In the Evaluate Sort Expression in this scope field, select Detail Scope. 7. Click OK to close the Textbox Properties window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-41
Report Design in Microsoft Dynamics® NAV 2009
Lab 2.3 - Adding a Document Map In this lab you will add a document map to the report. You will learn how to add a named document map Scenario During his conversations with Kevin, Mort notices that Kevin pays a lot of attention to the report navigation. In the meantime, Mort has found out about document maps, a built-in feature of Microsoft SQL Server Reporting Services that allows the user to quickly navigate the contents of a report. He decides to implement a document map in the Sales by Salesperson report.
Challenge Yourself! Add a document map to the report with the following specifications: •
The document map should be labeled "Sales by Salesperson"
•
The document map should contain the following data levels: Salesperson Code, Country Code, Customer Name
Need a Little Help? 1. Define a Name for the Data Region Control in the Document Map 2. Add Fields to the Document Map
Step by Step Define a Name for the Data Region Control in the Document Map 1. Open the RDLC layout of report 123456700 in Visual Studio Report Designer. 2. Right-click the top left corner of the table for and select Properties to open the Table Properties window. 3. On the Navigation tab, enter "Sales by Salesperson" in the Document map label field. This will appear as a label for the current table (data region control) in the report. This is very convenient if the report contains several tables with a document map.
2-42
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Add Fields to the Document Map 1. On the Groups tab, select the table1_group1 group and click Edit. The Grouping and Sorting Properties window will appear. 2. On the General tab, select =Fields!Customer__Salesperson_Code_.Value in the Document map label field. 3. Click OK to close the Grouping and Sorting Properties window and return to the Table Properties window. 4. On the Groups tab, select the table1_group2 group and click Edit. The Grouping and Sorting Properties window will appear. 5. On the General tab, select =Fields!Customer__Country_Region_Code_.Value in the Document map label field. 6. Click OK to close the Grouping and Sorting Properties window and return to the Table Properties window. 7. On the Groups tab, select the table1_group3 group and click Edit. The Grouping and Sorting Properties window will appear. 8. On the General tab, select =Fields!Customer_Name.Value in the Document map label field. 9. Click OK to close the Grouping and Sorting Properties window and return to the Table Properties window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-43
Report Design in Microsoft Dynamics® NAV 2009
Lab 2.4 - Adding Pictures to a Report In this lab you will work with pictures. You will use embedded images and database pictures. In addition, you will add a report header and use the ReportItems collection to add data fields to the header. Scenario Michael, the account manager, needs to go a new customer. In order to give the customer a running start, Michael wants to provide the customer with an Item Catalog. Michael arranges a meeting with Mort to explain the specifications of the Item Catalog. The report should have a header (printed on every page). Apart from the report title, the header should contain the Cronus company logo as an embedded picture. Furthermore, the basic company info such as company name, address, post code, city, country and VAT Registration No. should be included. The list should also include the pictures of the items. However, as not all items have pictures, you will include the picture as a hidden field, that can be made visible when the user clicks the Item No. Mort knows that an unfinished version of a similar report already exists for the classic client. He uses the report as a starting point to develop the RDLC report layout.
Challenge Yourself! Create an Item Catalog report with the following specifications •
The body contains the following item information: No., Description, Base Unit of Measure, Unit Price, Inventory and Picture.
•
The Picture can be made visible by clicking the Item No.
•
The header contains the report title, basic company information (company name, address, post code, city, country and VAT Registration No.) and the Cronus logo (as an embedded picture). The header must appear on every page.
Need a Little Help? 1. 2. 3. 4. 5. 6. 7.
2-44
Import the object. Export the Company Logo from the Demo Database Create the Table in the RoleTailored Client Layout Set the Format for the Unit Price Field Set the Format for the Inventory Field Change the Layout of the Table Header Cells Add the Picture Field to the Table
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 8. 9. 10. 11. 12. 13. 14. 15. 16.
Set the Visibility for the Picture Field Embed the Company Logo Picture in the Report. Add a Page Header Section to the Report. Add an Image Control for the Company Logo to the Report Add the Report Title to the Page Header Add (Hidden) Company Information to the Table Resize the Hidden Columns Add Textboxes for the Company Information to the Page Header Run the Report
Step by Step Import the object 1. 2. 3. 4. 5. 6. 7. 8. 9.
Open the Microsoft Dynamics NAV 2009 demo database. Open the CRONUS International Ltd. demo company. Select Tools, Object Designer to open the Object Designer.. Select File, Import. Browse to the report R123456704.fob. Click OK to start the import. In the dialog box, choose to open the Import Worksheet window. In the Action column, verify that the action is set to Create. Click OK to import the object in the database.
Export the Company Logo from the Demo Database 1. Open the Cronus International Ltd. company in Microsoft Dynamics NAV. 2. In the Object Designer, run form 1, Company Information. 3. Click Picture, Export. 4. Save the company logo as bitmap (cronus.bmp) on the Windows Desktop. 5. Close the Company Information window.
Create the Table in the RoleTailored Client Layout 1. 2. 3. 4.
Open report 123456704 in Visual Studio Report Designer. Add a table to the Body section. Add two columns to the table. In the Website Data Sources window, select Item__No__ and drag it to the first cell in the table detail row. 5. In the Website Data Sources window, select Item_Description and drag it to the second cell in the table detail row.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-45
Report Design in Microsoft Dynamics® NAV 2009 6. In the Website Data Sources window, select Item__Base_Unit_Of_Measure_ and drag it to the third cell in the table detail row. 7. In the Website Data Sources window, select Item__Unit_Price_ and drag it to the fourth cell in the table detail row. 8. In the Website Data Sources window, select Item_Inventory and drag it to the fifth cell in the table detail row.
Set the Format for the Unit Price Field 1. On the table detail row, select the cell containing the Unit Price. 2. Right-click the cell and select Properties. 3. On the Format tab, in the Format Code field, select the proper format code using the Expression windwo: =Fields!Item__Unit_Price_Format.Value. 4. Click OK to close the Textbox Properties window.
Set the Format for the Inventory Field 1. On the table detail row, select the cell containing the Inventory. 2. Right-click the cell and select Properties. 3. On the Format tab, in the Format Code field, select the proper format code using the Expression window: =Fields!Item_InventoryFormat.Value. 4. Click OK to close the Textbox Properties window.
Change the Layout of the Table Header Cells 1. Click the row handle for the table header row 2. Set the FontWeight property in the (Font collection) to Bold. 3. Set the VerticalAlign property to Bottom.
Add the Picture Field to the Table 1. Add a column to the right side of the table. 2. From the Toolbox window drag an Image control to the new column. 3. In the Properties window, set the Source property to Database. 4. In the Properties window, set the Value property to Fields!Item_Item_Picture.Value. 5. In the Properties window, set the MIME Type property to image/bmp.
2-46
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features Set the Visibility for the Picture Field 1. In the Properties window, in the Visibility property collection, set the Hidden property to True. 2. In the Properties window, in the Visibility property collection, set the ToggleItem property to Item__No__.
Embed the Company Logo Picture in the Report 1. 2. 3. 4.
In the Report menu, select Embedded Images. In the Embedded Images window, select New. Browse to the Windows Desktop and select cronus.bmp. Click OK to import the picture in the report.
Add a Page Header Section to the Report 1. In the Report menu, select Page Header.
Add an Image Control for the Company Logo to the Report 1. In the Toolbox window, select the Image control and insert it in the page header section. 2. Select the Image control. 3. In the Properties window, set the Location property to 10,5cm; 0,25cm. 4. In the Properties window, set the Source property to Embedded. 5. In the Properties window, set the Value property to cronus. (The MIME Type property will be filled automatically.) 6. In the Properties window, check that the Sizing property is set to Autosize.
Add the Report Title to the Page Header 1. In the Toolbox window, select the Textbox control and insert it in the top left corner of the page header section. 2. Select the Textbox control. 3. Set the value property to "Item Catalog" 4. Set the FontSize property to 18pt. 5. Set the Color property to RoyalBlue.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-47
Report Design in Microsoft Dynamics® NAV 2009 Add (Hidden) Company Information to the Table 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
Add a new column to the right side of the table. Select the column by clicking the column handle. In the Properties window, set the Hidden property to True. In the Properties window, set the Color property to Red. Add five new columns to the right of the column created in step 1. In the dataset, select CompInfo_Name and drag it to the first of the six hidden columns. In the dataset, select CompInfo_Address and drag it to the next hidden column. In the dataset, select CompInfo__Post_Code_ and drag it to the next hidden column. In the dataset, select CompInfo_City and drag it to the next hidden column. In the dataset, select CompInfo__Country_Region_Code_ and drag it to the next hidden column. In the dataset, select CompInfo__VAT_Registration_No__ and drag it to the last hidden column.
Resize the Hidden Columns 1. Select the six hidden columns. 2. Resize the columns with the mouse or by setting the Width property (in the Properties window) to 0,25cm
Add Textboxes for the Company Information to the Page Header 1. Add 6 new textboxes to the Page Header. Arrange them in the same way as in the header section of the Classic report. 2. Right-click the first textbox and select Expression. 3. In the Build an expression using Visual Basic language syntax field, enter =ReportItems!CompInfo_Name.Value. 4. Click OK to close the Expression window. 5. Right-click the next textbox and select Expression. 6. In the Build an expression using Visual Basic language syntax field, enter =ReportItems!CompInfo_Address.Value. 7. Click OK to close the Expression window. 8. Right-click the next textbox and select Expression. 9. In the Build an expression using Visual Basic language syntax field, enter =ReportItems!CompInfo__Post_Code_.Value. 10. Click OK to close the Expression window.
2-48
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 11. Right-click the next textbox and select Expression. 12. In the Build an expression using Visual Basic language syntax field, enter =ReportItems!CompInfo_City.Value. 13. Click OK to close the Expression window. 14. Right-click the next textbox and select Expression. 15. In the Build an expression using Visual Basic language syntax field, enter =ReportItems!CompInfo__Country_Region_Code_.Value. 16. Click OK to close the Expression window. 17. Right-click the next textbox and select Expression. 18. In the Build an expression using Visual Basic language syntax field, enter =ReportItems!CompInfo__VAT_Registration_No__.Value. 19. Click OK to close the Expression window.
Run the Report 1. 2. 3. 4.
Exit Visual Studio. Save and import the RDLC changes. Save and compile the report in the Report Designer. Run the report from the Start, Run menu.
Summary In this chapter you learned to work with the enriched functionalities of the new reporting solution. You saw the different types of headers and footers and how to activate them. Furthermore you learned how to use interactive sorting, visibility options, document maps and different types of pictures. Finally, you discovered the ReportItems collection.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-49
Report Design in Microsoft Dynamics® NAV 2009
Test Your Knowledge Test your knowledge with the following questions. 1. Which header sections are not supported by Visual Studio Report Designer? ( ) Page Header ( ) Group Header ( ) Transport Header ( ) Table Header 2. Which properties are not supported by Visual Studio Report Designer? ( ) PrintOnEveryPage ( ) RepeatOnNewPage ( ) RepeatHeaderOnNewPage ( ) PlaceInBottom 3. In which windows can you delete a Group Header? (Select all that apply) ( ) Properties window ( ) Table Properties window ( ) Grouping and Sorting Properties window ( ) Header Properties window 4. What is not a valid option for the Source property of an Image control? ( ) Internal ( ) External ( ) Embedded ( ) Database 5. Which controls cannot be added to a Page Header section? ( ) Chart ( ) Label ( ) Textbox ( ) List 6. Which sections can contain database pictures? ( ) Body Sections ( ) Page Header and Page Footer sections ( ) Page Header, Body and Page Footer sections ( ) None of the answers is correct.
2-50
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features 7. Which properties can be used to set the background and the foreground color of a control? ( ) BackgroundColor and ForegroundColor ( ) BackgroundColor and TextColor ( ) BackgroundColor and Color ( ) BackgroundColor and CellColor 8. What is the ReportItems collection? ( ) A collection of all textboxes in a report. ( ) A collection of all controls in a report. ( ) A collection of all sections in a report. ( ) A collection of all reports
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-51
Report Design in Microsoft Dynamics® NAV 2009
Quick Interaction: Lessons Learned Take a moment and write down three Key Points you have learned from this chapter 1.
2.
3.
2-52
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 2: Interactive Features
Solutions Test Your Knowledge 1. Which header sections are not supported by Visual Studio Report Designer? ( ) Page Header ( ) Group Header ( ) Transport Header (•) Table Header 2. Which properties are not supported by Visual Studio Report Designer? (√) PrintOnEveryPage ( ) RepeatOnNewPage ( ) RepeatHeaderOnNewPage (√) PlaceInBottom 3. In which windows can you delete a Group Header? (Select all that apply) ( ) Properties window (√) Table Properties window (√) Grouping and Sorting Properties window ( ) Header Properties window 4. What is not a valid option for the Source property of an Image control? (•) Internal ( ) External ( ) Embedded ( ) Database 5. Which controls cannot be added to a Page Header section? (√) Chart ( ) Label ( ) Textbox (√) List 6. Which sections can contain database pictures? ( ) Body Sections ( ) Page Header and Page Footer sections (•) Page Header, Body and Page Footer sections ( ) None of the answers is correct.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
2-53
Report Design in Microsoft Dynamics® NAV 2009 7. Which properties can be used to set the background and the foreground color of a control? ( ) BackgroundColor and ForegroundColor ( ) BackgroundColor and TextColor (•) BackgroundColor and Color ( ) BackgroundColor and CellColor 8. What is the ReportItems collection? (•) A collection of all textboxes in a report. ( ) A collection of all controls in a report. ( ) A collection of all sections in a report. ( ) A collection of all reports
2-54
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report
CHAPTER 3: ADDING CODE TO A REPORT Objectives The objectives are: •
Examine how coding can be used in reports for the Classic and the RoleTailored Client
•
Work with expressions.
•
Learn how to use expressions
•
Examine frequently used expressions
•
Examine the components of the Sales Invoice report.
Introduction When creating reports in Microsoft Dynamics® NAV start by defining the data model for the report by filling in the data item(s). Then, for each data item, define sections, the same way as in the previous chapter. Besides sections, for every data item there are also triggers available. Triggers can contain C/AL code that is executed when the trigger fires. The report itself always has the following triggers: •
OnInitReport()
•
OnPreReport()
•
OnPostReport()
For every data item that you add in the DataItem designer window the following triggers are available: •
OnPreDataItem()
•
OnAfterGetRecord()
•
OnPostDataItem()
Then, for every section in the Section Designer you have the following triggers for Classic reports: •
OnPreSection()
•
OnPostSection()
In reports, triggers are typically used to perform calculations and to control whether to output sections. Triggers allow you to control how data is selected and retrieved in a more complex and effective way than you can achieve by using properties.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-1
Report Design in Microsoft Dynamics® NAV 2009 In Report Definition Language Client-side (RDLC) report layouts, code on section triggers is not supported. This means that all the code that is developed in section triggers will not be executed in the RDLC report. All of the code that is still required to run for the RDLC reports will have to be moved to other triggers or you can create custom code in Microsoft® Visual Studio® 2008 Report Designer. Later in this chapter some common functions used in section triggers will be explained. You will also see how they can be redesigned to work in the RDLC reports. An RDLC report does not contain triggers. Instead, you can make use of expressions. Expressions are related to properties in RDLC reports. To summarize, all of the code in report triggers will still be executed for the RDLC reports, except the code in section triggers. This chapter will focus on what is important to know for developing RDLC reports.
Using Variables and C/AL Code in a Report The reports built in the previous chapters are designed using the designers, controls and properties. In Classic reports it is also possible to add code. The code is used for advanced report functionalities that cannot be achieved using properties. It can be used for retrieving and calculating data, but also for formatting purposes (and dynamically hiding and showing data sections). Code can be written using the C/AL Editor on different levels: •
Report triggers
•
Data item triggers
•
Section triggers (Classic reports only)
•
Request form triggers
•
Request form control triggers
•
Request page triggers
•
Request page control triggers
Previous chapters described how the logical design of a report applies to both Classic and RDLC report layouts. If you use code to filter or sort a specific data item, the code will be reflected in the dataset that is generated.
3-2
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report But not all code is written on the data item level. Many reports have a request options form with options that affect the way a report is printed. Well-known options are: Show details, Print amounts in Local Currency, Top X (where X can be a number chosen by the user such as Top 5, Top 10), Show Sales (LCY) or Balance (LCY). The information from the request form is stored in variables that are evaluated in runtime. Often the variables are evaluated on the data item level. However they sometimes are evaluated on the section trigger level, to determine whether a section is to be printed. Since, conversely, not all functionalities of the Classic Report Designer are supported in Visual Studio Report Designer, the question for you as a developer is: how to design a report that offers the same functionalities and information on both platforms? Even more: how to build a report that uses the new enhanced reporting features?
Verify Code on a Report By now it is clear that code that is supported on the Classic report layouts is not always supported on the client report definition (RDLC) report layouts. To use the RDLC layout of a report, first verify that all code on your report is supported in the RDLC layout. If the code on your report is not supported, then you must move or modify the code. For example, code that retrieves or calculates data in the OnPreSection trigger can be moved to the OnAfterGetRecord trigger of the data item. But not all code can be moved. For example, the CurrReport.SHOWOUTPUT can only be used in section triggers. In these cases, the code needs to be replaced by an alternative solution to achieve the same result. (You can use an expression for the Visibility property instead.) If the RDLC report layout and the Classic report layout contain different information, then you will also have to add extra controls to the Body section of the Classic report to have the fields included in the dataset. When redesigning the code, you can use the ISSERVICETIER function to distinguish between code that is executed for the Classic client and code that is executed for the RoleTailored client. IF IsServiceTier THEN BEGIN ; END ELSE BEGIN ; END;
This lesson will describe a number of typical scenarios from Classic reports that require design changes.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-3
Report Design in Microsoft Dynamics® NAV 2009 Redesign Section Triggers Verify that the report does not have code on any section triggers. If a report does have code on a section trigger, determine how to achieve the same functionality by moving or modifying the code or by using new report layout functionality:
Code that evaluates the visibility of a section These occurrences can often be replaced by adding a variable on the request page and using an expression that includes this variable in the Visibility property of the table row or control.
Code that evaluates the format of controls Code that evaluates the format of specific controls can be replaced by using expressions in different properties and property collections: BackgroundColor, Color, Font, Size, and TextAlign.
Code that calculates information In this case you can move the code into a separate function in the Classic report or even in the RDLC layout. The following code example shows a function that calculates percentages. Shared Pct as Decimal Public Function CalcPct(Amount1 as Decimal, Amount2 as Decimal) as Decimal If Amount2 0 Then Pct = Amount1 / Amount2 * 100 Else Pct = 0 End If REM Rounding precision = 0.1 Return ROUND(10*Pct)/10 End Function
If adding the function to the RDLC Layout, remember to set the Value property of the textboxes that use the function to the following expression: =Code.CalcPct(AmountParameter,ProfitParameter).
Check the Value of Printed Variables In a Classic client report layout, when a Boolean value appears on a report, the value is printed as "yes" or "no" in the target language. In a client report definition (RDLC) report layout, when a Boolean value appears on a report, the value is printed as "true" or "false" in the target language. In some cases, you may want to change the printed value of a Boolean variable in an RDLC report layout to "yes" or "no" instead of "true" or "false." For example, you may have Classic and RDLC report layouts and require the same wording in both layouts.
3-4
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report This can be achieved in two ways: either you change the SourceExpr property of the textbox showing the Boolean variable to FORMAT(BooleanVariable), or you set the Value property of the textbox in the RDLC report layout to an expression like =IiF(Fields!BooleanVariable.Value = False, "No", "Yes"). The same applies to Date values. When creating a client report definition (RDLC) layout for a report, you must modify date values so that they are formatted correctly. You can use a similar procedure as for the Boolean variables to verify or change the format of a date. Either you set the format in the classic report using the FORMAT() instruction, or you can use an expression to define the format of the date yourself. Date formats defined in the Classic design will overrule date formats specified in Visual Studio.
Check Option Fields In the Classic client you can use both the numeric value and the text representation to check the value that is selected for an option variable. Be aware that the RDLC report layout does not provide this functionality: strings will be handled as normal strings. It is highly recommended to work with the numeric value of the option variables in the RDLC report layouts, so that multi-language functionality will not be an issue.
Working with Report Expressions Expressions are widely used in a report for various purposes. They can be used for data manipulation (retrieve, calculate, format, group, sort and filter data) and formatting purposes. In SQL Server Reporting Services and also in client-side reporting, expressions are used to provide dynamic flexibility for controlling the content and appearance of a report. In most cases, expressions are used to get the following kinds of functionality in your report: •
Aggregations on data to show the sum, average, percentage, or product of a particular row set.
•
Conditional formatting, where text or background formatting changes based on logic you define.
•
Conditional text, where a report title varies depending on who is running the report.
•
Concatenated text from multiple dataset fields and constants.
•
Data filtering (after it is retrieved from the data source).
•
Data grouping and sorting.
•
Dynamic page header and page footer content.
On the report design surface, expressions appear as simple or complex expressions.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-5
Report Design in Microsoft Dynamics® NAV 2009 Simple expressions contain a reference to a single dataset field or built-in field. Simple expressions are created for you automatically (for example, when dragging a field from a dataset onto a text box), or you can type them directly into a data region cell or text box on the design surface. Complex expressions can contain multiple built-in references, operators, and function calls combined with simple expressions. An expression is written in Microsoft® Visual Basic®. An expression begins with an equal sign (=) and consists of references to dataset fields, constants, operators, functions, and other built-in report collections. During report processing, each expression evaluates to a single value that replaces the expression when a report is rendered. Knowing how to create and use expressions is a fundamental skill that will enable you to create rich full-featured reports.
How to Create Expressions You can create expressions in a report definition in two ways: either by using the Expression window, or by typing the expression syntax directly into a textbox, a property in the Properties window, or a group, sort and filter expression field. Using the Expression window has many advantages over manually entering the expressions. Apart from a large work area, it offers context-sensitive global collection item choices, statement completion, and syntax checking. Expressions are created using Microsoft Visual Basic language syntax. You can create expressions either by entering the expression manually or by composing an expression in the Expression window. In this window you can use a number of built-in collections to create your expressions.
3-6
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The Expression Editor When you open the Expression window, the following dialog box is displayed.
FIGURE 3.1 THE EXPRESSION WINDOW
The Expression window can be used to add and edit expressions. It is divided into a number of panes. The top pane, the expression pane, shows the current expression for the selected textbox or property. You can edit the expression in the pane by using the keyboard and by double-clicking items in the bottom panes. The bottom middle pane, the Item pane, contains all items that are available in the selected category. The contents of the pane are updated whenever a new category is selected in the Category pane. For example, the Globals category contains items such as ExecutionTime, UserId and Language. At the right side you can have one big pane, the Field pane, or two smaller panes (the Description and the Example pane). Which panes appear depends on the selected Category. The Field pane contains all elements that are available in the selected Item and Category. The contents of the Field pane are updated whenever you select a new Item. If the selected Item does not contain any fields, the Field pane will be replaced by the Description and Example panes. The Description pane shows a description of the selected Item, while the Example pane displays an example of the selected item.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-7
Report Design in Microsoft Dynamics® NAV 2009 For example, when selecting the Program Flow category (under Common Functions), the Item category will show the three functions in the category. The Description pane will show a small description of the selected Item, and the Example pane illustrates the syntax of the selected function. When building an expression, you can double-click any element in the bottom panes to have it inserted automatically in the expression pane. As the expression pane suggests, expressions can be built further using Microsoft Visual Basic language syntax. The expression pane supports features such as IntelliSense, statement completion, colored syntax and syntax checking, so that you can easily detect syntax errors. You can move and resize the Expression Editor to have a larger work surface. In some windows (for example, on the Sorting tab in the Table Properties window) you can create multiple expressions that will be combined during report processing. However, the Expression window allows you to edit only one expression at a time.
Accessing the Expressions Window The Expression editor can be accessed in various ways, depending on the current position in the Visual Studio Report Designer. You can open the Expression Editor for the following items:
3-8
•
A text box on a report.
•
A property in the Properties page.
•
A Groups tab on data region properties.
•
A Sorting tab on data region properties.
•
A Filter tab for datasets, data regions, or data region groupings.
•
A document map label on a data region group.
•
A parent group on a data region group.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report On the design surface, you can right-click any textbox control and select Expression, as shown in the following figure.
FIGURE 3.2 THE EXPRESSION WINDOW
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-9
Report Design in Microsoft Dynamics® NAV 2009 Several properties in the Properties window, such as Visibility, BackgroundColor and Value, support both fixed options and expressions as a first option in the drop-down list. Select <Expression> in the drop-down list to enter an expression in the Value column for a property.
FIGURE 3.3 THE PROPERTIES WINDOW
Expressions can also be entered in various dialog boxes such as the Grouping and Sorting Properties and the Table Properties window. In these windows, expressions can either be selected directly from a drop-down list, or they can be entered by clicking the fx button to set specific properties. For example, in the Table Properties window, on the General tab, the fx button is available to define Tooltips.
Valid Expression References The previous section explained that you can build an expression using a variety of functions from different built-in categories. In Chapter 2, you already worked with the ReportItems collection. The following table shows the types of references that you can include in a report expression.
3-10
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The table indicates which of these references are built-in, and which references you must identify to the report processor so that the function calls can be resolved during report processing. Items
Description of functions and how to reference them
Reporting Functions
Built-in. Functions that provide aggregate values on report items, and other utility functions that support aggregation. The Aggregate implementation is supplied by each data provider.
Reporting Collections
Built-in. Globals, User, Fields, ReportItems, Datasets.
Custom Code
Built-in. Add your Visual Basic code through the Report Properties menu, Code tab. You can define public constants, variables, subroutines, and functions for your use in each report definition.
Visual Basic Run-time Library
Built-in.
System.Math
Built-in.
System.Convert
Built-in.
.NET Framework (common language runtime) Classes
Add fully qualified references in your expression. For example, System.Text.StringBuilder.
Besides using the built-in functions, you can add additional functions to your report, by adding code or external references to your report. To add custom code to your report, select Report, and then select Report Properties in Visual Studio Report Designer. On the Code tab, you can add the custom code (variables, functions, procedures, and so on) to enrich your report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-11
Report Design in Microsoft Dynamics® NAV 2009 When you open Visual Studio Report Designer to create a report for the RoleTailored client, a number of functions are automatically added to the Code tab.
FIGURE 3.4 THE CODE TAB OF THE REPORT PROPERTIES WINDOW
The functions that are added all relate to presentation and formatting of data. Functions that are part of the Classic report layout are not converted automatically to functions on the Code tab. Although you can add any code to the report using the Code tab, it is highly recommended not to include code that is part of the report's business logic. If the report is used by both Classic client and RoleTailored client users, you will have to duplicate the code and it then becomes more difficult to maintain the source code. Expression always start with the "=" sign. This indicates that the statement following the equal sign is an expression that will be evaluated by the reporting engine. Most expressions consist of a single constant value. For example, the FontName property of a textbox can have a number of constant values, such as Arial, Tahoma, Verdana, and so on. The Width property is less restrictive: the values are not predefined. You can also use a combination of functions, variables and constants to build a more complex expression. To refer to a collection or element from an expression, use the standard Visual Basic syntax. For example, to refer to the value of a specific field (in the Fields collection), use the =Fields("FieldName").Value expression. An alternative way of referencing the same value is to use =Fields!FieldName.Value. In this case the (parent) collection and the (child) element are concatenated by an exclamation mark. An element and its properties are always separated by a "." (period). Syntax errors are detected and indicated automatically. However, syntax errors do not keep you from importing the RDLC data into Microsoft Dynamics NAV.
3-12
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report When you try to save and compile the report in the Object Designer, some errors in the RDLC report layout might be indicated. For example, if a wrong syntax for the IIF() statement is used, or if the Value property of a textbox in the Page Header section is set to a data field from the dataset, you will get an error message. Other errors might appear when the report is run. NOTE: Apart from the items in the table above, it is also possible to add custom assemblies and classes to reports. However, only trusted managed assemblies are supported. More information on creating trusted managed assemblies can be found on http://msdn.microsoft.com.
Understanding and Using Simple and Complex Expressions The previous lesson described how expressions are widely used in reports for various purposes. Knowing how to create and use expressions is a fundamental skill that will enable you to create rich full-featured reports. This lesson will describe the different data collections that can be used in expressions.
Using Constant Collections in Expressions The Constants collection is mostly used in simple expressions. Simple expressions consist of the "=" sign, followed by a single value. They are often used to set properties throughout the report. The content of the Constant category depends on the selected property. When you select the Color property of a text box, it contains the possible colors. When you select the Hidden property (in the Visibility property collection), the category contains two constants: True and False.
Using Global Collections in Expressions Reporting Services provides the following global collections that you can reference from expressions: Constants, DataSets, DataSources, Fields, Globals, Parameters, ReportItems, and User. (Since the RoleTailored client uses clientside reporting, the Parameters and DataSources collections will either always be empty or not available in Visual Studio Report Designer.)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-13
Report Design in Microsoft Dynamics® NAV 2009 The following table describes each global collection and notes when you can reference the collection from an expression. Global Collection
Description
Fields
Represents the collection of fields of the dataset that are available to the report. Available after data is retrieved from Microsoft Dynamics NAV into the dataset.
ReportIte ms
Represents the collection of text boxes for the report item, such as the text boxes contained within a table data region, page header, or page footer. Available during report processing.
User
Represents a collection of data about the user running the report, such as the language setting or the user ID. Always available. User!UserID is frequently used to filter results in reports. User!Language is used to make specific settings dependent on the language of the user.
DataSets
Represents the collection of datasets referenced from the body of a report definition. Does not include data sources used only in page headers or page footers.
Globals
Represents global variables useful for reports, such as the report name or page number. Always available.
The next lesson describes in more detail some of the frequently used functions.
Using Report Functions in Expressions ReportViewer provides built-in functions that you can use in report expressions. Built-in functions can be used in expressions that you include in client report definition (.rdlc) files and in report definition (.rdl) files that are processed on a SQL Server Reporting Services report server. Support for the functions is provided by the ReportViewer controls and Reporting Services. You can use built-in functions within expressions to manipulate the data within report items, properties, and other areas in the report. Built-in functions are used to aggregate data in datasets, data regions, and groups, and return other data. You can use aggregate functions in expressions for any report item. All data used for an aggregate calculation must be the same data type. To convert data that has multiple numeric data types to the same data type, use conversion functions like CInt(), CDbl() or CDec().
3-14
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The following table describes the aggregate functions that are supported by Reporting Services. Function
Description
Aggregate
Returns a custom aggregate of the specified expression, as defined by the data provider.
Avg
Returns the average of all non-null values from the specified expression.
Count
Returns a count of the non-null values from the specified expression.
CountDistinct
Returns a count of all non-null distinct values from the specified expression.
CountRows
Returns a count of rows within the specified scope.
First
Returns the first value from the specified expression.
Last
Returns the last value from the specified expression.
Max
Returns the maximum value from all non-null values of the specified expression.
Min
Returns the minimum value from all non-null values of the specified expression.
RowNumber
Returns a running count of all rows in the specified scope.
RunningValue
Uses a specified function to return a running aggregate of the specified expression.
StDev
Returns the standard deviation of all non-null values of the specified expression.
StDevP
Returns the population standard deviation of all non-null values of the specified expression.
Sum
Returns a sum of the values of the specified expression.
Var
Returns the variance of all non-null values of the specified expression.
VarP
Returns the population variance of all non-null values of the specified expression.
Reporting Services provides the following additional aggregate functions that you can use within expressions. Function
Description
InScope
Indicates whether the current instance of an item is within the specified scope.
Level
Returns the current level of depth in a recursive hierarchy.
Previous
Returns the previous instance from the specified scope.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-15
Report Design in Microsoft Dynamics® NAV 2009 Each aggregate function uses the Scope parameter, which defines the scope in which the aggregate function is performed. A valid scope is the name of a grouping, dataset, or data region. Only groupings or data regions that directly or indirectly contain the expression can be used as a scope. For expressions within data regions, Scope is optional for all aggregate functions. If omitting the Scope parameter, the scope of the aggregate is the innermost data region or grouping to which the report item belongs. •
Specifying a scope of Nothing sets the scope to the outermost data region to which the report item belongs.
•
For expressions outside of data regions, Scope refers to a data table or business object.
•
If a report contains more than one dataset, Scope is required.
•
If a report contains only one dataset and Scope is omitted, the scope is set to the dataset.
•
The Nothing keyword cannot be specified for report items outside of a data region.
•
The Scope parameter cannot be used in page headers or footers.
Expression Examples Expressions are frequently used in reports. These include expressions to change the appearance of data in a report, change properties of report items, and affect how data is retrieved (filtering and sorting expressions). Many expressions in a report contain functions. You can format data, apply logic, and access report metadata using these functions: •
String Functions
•
Date and Time Functions
•
Conversion Functions
•
Decision Functions
•
Report Functions
This lesson describes some expressions that can be used for common tasks in a report.
String Functions String functions can be used to manipulate string values in a report. You can use a number of functions to do the following tasks:
3-16
•
Concatenate fields and constants by using concatenation operators and Visual Basic constants.
•
Format dates and numbers.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report •
Return substrings.
•
Change the format of strings.
Concatenate Fields and Constants by Using Concatenation Operators and Visual Basic Constants The following expression returns two fields, each on a separate line in the same text box:
=Fields!FirstName.Value & vbCrLf & Fields!LastName.Value
Format Dates and Numbers Format dates and numbers in a string with the Format() function. The following expression displays values of the StartDate and EndDate fields in long date format:
=" Between " & Format(Fields!StartDate.Value, "D") & " And " & Format(Fields!EndDate.Value, "D")
If the text box contains only a date or number, use the Format property of the text box to apply formatting instead of the Format function within the text box.
Return Substrings The Right(), Len(), and InStr() functions are useful for returning a substring, for example, trimming DOMAIN\username to just the user name. The following expression returns the part of the string to the right of a backslash (\) character from a report global named UserID:
=Right(User!UserID, Len(User!UserID) - InStr(User!UserID, "\"))
Change the Format of Strings The Regex functions from the .NET Framework System.Text.RegularExpressions are useful for changing the format of existing strings, for example, formatting a telephone number. The following expression uses the Replace function to change the format of a ten-digit telephone number in a field from "nnn-nnn-nnnn" to "(nnn) nnn-nnnn":
=System.Text.RegularExpressions.Regex.Replace(Fields!Phone. Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-17
Report Design in Microsoft Dynamics® NAV 2009 Date and Time Functions Date functions are used to analyze and format a date in a report. To format a date, you can either select a predefined format or define a custom format yourself using a number of date and time functions, such as : DatePart, Year, Month, MonthName, Day, Weekday, WeekdayName, Hour, Minute, Second. You can also perform date calculations (using functions such as DateDiff() and DateAdd()) and convert a string to a date using CDate(). Now() returns a Date value containing the current date and time according to your system.
Examples The Today function provides the current date. This expression is used in a text box to display the date on the report, or in a parameter to filter data based on the current date. =Today()
The DateAdd() function is useful for supplying a range of dates based on a single parameter. The following expression provides a date that is six months after the date from a field named StartDate. =DateAdd(DateInterval.Month, 6, Fields!StartDate.Value)
The Year() function displays the year for a particular date. You can use this to group dates together or to display the year as a label for a set of dates. This expression provides the year for a given group of sales order dates. The Month() function and other functions are also used to manipulate dates. For more information, see the Functions (http://msdn.microsoft.com/enus/library/3ca8tfek(VS.85).aspx) topic in the Visual Basic documentation. =Year(Fields!OrderDate.Value)
Conversion Functions You can use Visual Basic functions to convert a field from one data type to a different data type. Conversion functions are used to convert the default data type for a field to the data type needed for calculations or to combine text. Examples are CInt, CStr, CDate, CDec, CDbl, CBool, CLng, CSng, CShort. The following expression converts the constant 500 to type Decimal: =CDec(500)
3-18
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Decision Functions Decision functions allow evaluating a logical or relational condition and return a specific value based on the result of the evaluation. The IIF() function returns one of two values depending on whether the expression is true or not. The following expression uses the IIF() function to return a Boolean value of True if the value of LineTotal exceeds 100. Otherwise it returns False: =IIF(Fields!LineTotal.Value > 100, True, False)
You can use multiple IIF() functions (also known as "nested IIFs") to return one of three values depending on the value of PercentCompleted. The following expression can be placed in the fill color of a text box to change the background color depending on the value in the text box. =IIF(Fields!PercentCompleted.Value >= 10, "Green", IIF(Fields!PercentCompleted.Value >= 1, "Blue", "Red"))
Values that are greater than or equal to 10 display with a green background, values between one and nine display with a blue background, and a value that is less than one displays with a red background. A different way to get the same functionality is to use the Switch() function. The Switch() function is useful when you have three or more conditions to test. The Switch() function returns the value associated with the first expression in a series that evaluates to true: =Switch(Fields!PercentCompleted.Value >= 10, "Green", Fields!PercentCompleted.Value >= 1, "Blue", Fields!PercentCompleted.Value = 1, "Yellow", Fields!PercentCompleted.Value 7,"Red","Blue")
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-19
Report Design in Microsoft Dynamics® NAV 2009 Test the Null Value In the following example, you test the value of the PhoneNumber field. If the field is null (Nothing in Visual Basic), "No Value" is returned; otherwise the phone number value is returned. This expression can be used to control the value of a text box in a report item. =IIF(Fields!PhoneNumber.Value Is Nothing,"No Value",Fields!PhoneNumber.Value)
The following expression can be used to control the Hidden property of an image report item. In the following example, the image specified by the field [LargePhoto] is displayed only if the text value of the field is not null. =IIF(IsNothing(Fields!LargePhoto.Value),True,False)
Report Functions Reporting Services provides built-in functions for use in expressions to calculate aggregate data in datasets, data regions, and groups, and to retrieve other data values, such as the first or last value on a report page. Two of the most important functions are the Sum() and the RowNumber() function.
Sum() The Sum() function can total the values in a group or data region. This function can be useful in the header or footer of a group. The following expression displays the sum of data in the Order group or data region: =Sum(Fields!LineTotal.Value, "Order")
You can also use the Sum() function for conditional aggregate calculations. For example, if a dataset has a field that is named State with possible values Not Started, Started and Finished, the following expression, when placed in a group header, calculates the aggregate sum for only the value Finished:
RowNumber() The RowNumber() function, when used in a text box within a data region, displays the row number for each instance of the text box in which the expression appears. This function can be useful to number rows in a table. It can also be useful for more complex tasks, such as providing page breaks based on number of rows. The scope that you specify for RowNumber() controls when renumbering begins. The Nothing keyword indicates that the function will start counting at the first row in the outermost data region. To start counting within nested data regions, use the name of the data region. To start counting within a group, use the name of the group. =RowNumber(Nothing)
3-20
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The following piece of code is used to evaluate whether the record in a data region control called table1 is on an odd or even row number. =IIF(RowNumber("table1") Mod 2 = 0, "LimeGreen", "Transparent")
It can be used to work with alternating background colors.
Appearance of Report Data You can use expressions to manipulate how data appears on a report. For example, you can display the values of two fields in a single text box, display information about the report, or affect how page breaks are inserted in the report.
Page Headers and Footers When designing a report, you may want to display the name of the report and page number in the report footer. The following expression provides the name of the report and the time it is run. It can be placed in a text box in the report footer or in the body of the report. The time is formatted with the .NET Framework formatting string for short date: =Globals!ReportName & ", dated " & Format(Globals!ExecutionTime, "d")
The following expression, placed in a text box in the footer of a report, provides the page number and total pages in the report: ="Page " & Globals!PageNumber & " of " & Globals!TotalPages
Page Breaks In some reports, you may want to place a page break at the end of a specified number of rows instead of, or in addition to, on groups or report items. To do this, create a group that contains the groups or detail records you want, add a page break to the group, and then add a group expression to group by a specified number of rows. The following expression uses the Ceiling() function. When placed in the group expression, it assigns a number to each set of 25 rows. When a page break is defined for the group, this expression results in a page break every 25 rows. =Ceiling(RowNumber(Nothing)/25)
To allow the user to set a value for the number of rows per page, create a variable RowsPerPage (the number can be added as a variable to the request options page) and base the group expression on the variable, as shown in the following expression: =Ceiling(RowNumber(Nothing)/Fields!RowsPerPage.Value)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-21
Report Design in Microsoft Dynamics® NAV 2009 On the Group Header, remember to check the Page Break at End option. A similar technique is also used in the Sales Invoice report, to have multiple copies of the report printed. This will be explained in the next lesson.
Properties Expressions are not only used to display data in text boxes. They can also be used to change how properties are applied to report items. You can change style information for a report item, change its visibility, or use dynamic URLs. •
Formatting
•
Visibility
•
URLs
Formatting The following expression, when used in the Color property of a text box, changes the color of the text depending on the value of another field, in this case the Profit field: =IIF(Fields!Profit.Value < 0, "Red", "Black")
To refer to the value of the current field, use the Fields!FieldName syntax, or use the Visual Basic object Variable Me. The following expression, when used in the Color property of a textbox, changes the color of the text depending on the value of the proper field: =IIF(Me.Value < 0, "Red", "Black")
The following expression, when used in the BackgroundColor property of a report item in a data region, alternates the background color of each row between pale green and white: =IIF(RowNumber(Nothing) Mod 2, "PaleGreen", "White")
If using an expression for a specified scope (for example the table called Employees in the report, it might be necessary to indicate the dataset for the aggregate function: Therefore, replace the Nothing value by the name of the data region control that corresponds to the scope.
Visibility You can show and hide items in a report using the visibility properties for the report item. In a data region such as a table, you can initially hide detail rows based on the value in an expression.
3-22
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The following expression, when used for initial visibility of detail rows in a group, shows the detail rows for all sales exceeding 90 percent in the PctQuota field: =IIF(Fields!PctQuota.Value>.9, False, True)
The following expression, when set in the Hidden property of a table, shows the table only if it has more than 12 rows: =IIF(CountRows()>12, True, False)
The following expression, when set in the Hidden property of a column, shows the column only if the field exists in the report dataset after the data is retrieved from the data source: =IIF(Fields!Column_1.IsMissing, True, False)
URLs You can customize URLs by using report data and also conditionally control whether URLs are added as an action for a text box. The following expression, when used as an action on a text box, generates a customized URL that specifies the dataset field EmployeeID as a URL parameter. ="http://adventure-works/MyInfo?ID=" & Fields!EmployeeID.Value
The following expression conditionally controls whether to add a URL in a text box. This expression depends on a variable named IncludeURLs that allows a user to decide whether to include active URLs in a report. This expression is set as a Hyperlink action (select Properties, Navigation tab) on a text box. =IIF(Fields!IncludeURLs.Value, "http://adventureworks.com/productcatalog?ItemID=" & Fields!Item_No ,Nothing)
Custom Code You can use custom code in a report. Custom code is either embedded in a report or stored in a custom assembly which is used in the report. To add code to a report in Visual Studio Report Designer, select Report, then Report Properties. On the Code tab, you can create your own custom code (functions and variables) to enrich the report functionalities. It is recommended not to add custom code that executes business logic; instead, use it to add presentation related code.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-23
Report Design in Microsoft Dynamics® NAV 2009 Custom code is used to create workarounds because of the inability to use databound fields in the Page Header and Footer sections. In previous chapters, you used the ReportItems collection to retrieve data in the Page Header from a text box in the Body section. In a similar way, you can define custom functions and variables to do the following tasks: •
Collect data from the dataset and load it into custom (array) variables.
•
Retrieve the data from the arrays and display it in the controls.
This will be described in the next lesson about the Sales Invoice report. As an example, one of the most common calculations in reports tends to be division. When dividing numeric variables, you have to be careful with NULL and 0 (zero) values because dividing a variable by NULL or by 0 results in a runtime error and or, NaN being returned in the reports. (NaN stands for Not a Number; it is a value or symbol that is generated as the result of an operation on invalid input terms, especially in floating-point calculations. A typical example is calculating the square root of a negative number.) To avoid this, you can create a function that checks the terms and returns the numeric result or, if there is an accidental error, a user-friendly value. The sample division function can look like this: Public Shared Function Divide(Num1 as double, Num2 as double) AS object IF ISNOTHING(Num2) Or Num2 = 0 Then Divide ="n/a" ELSEIF Num1 = 0 THEN Divide = 0 ELSE Divide = Num1 / Num2 END IF End Function
You can then call this function from an expression like this: =Code.Divide(1, 0) Instead of calling the Code.Divide function, use an expression with an IIf() statement in each textbox where you want to calculate the division. Adding custom code increases the maintainability of your report code.
3-24
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report A similar example calls an embedded method called FixSpelling(), which substitutes "Bicycle" for all occurrences of the text "Bike" in the SubCategory field. The example assumes that the following function is embedded on the report's Code tab. Public Function FixSpelling(ByVal s As String) As String Dim strBuilder As New System.Text.StringBuilder(s) If s.Contains("Bike") Then strBuilder.Replace("Bike", "Bicycle") Return strBuilder.ToString() Else : Return s End If End Function
To have the values replaced at runtime for each record in the report, set the Value property of the SubCategory field to: =Code.FixSpelling(Fields!SubCategory.Value) The following example calls an embedded code method called ToUSD(), which converts the StandardCost field value to a dollar value: =Code.ToUSD(Fields!StandardCost.Value)
Custom Variables The following example shows how to define some custom constants and variables. Public Public Public Public
Const MyNote ="Authored by John Doe" Const NCopies As Int32 = 2 Dim MyVersion As String ="123.456" Dim MyDoubleVersion As Double = 123.456
Although custom constants and variables do not appear in the Expression Editor Constants view (which only displays built-in constants), you can add references to them from any expression, as shown in the following examples. These are treated as Variants. =Code.MyNote =Code.NCopies =Code.MyVersion =Code.MyDoubleVersion
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-25
Report Design in Microsoft Dynamics® NAV 2009 Adding Database Pictures to the Header Chapter 2 mentioned it is possible to add database pictures to the page header using code and expressions. The following steps show how to do this. 1. 2. 3. 4.
In Visual Studio Report Designer, add a textbox to the Body section. In the Properties window, set the Name to CompanyPicture. In the Properties window, set the Hidden property to True. In the Properties window, set the Color property to Red. (This way you can distinguish the hidden from the visible controls.) 5. In the Properties window, set the Value property to: =Convert.ToBase64String(Fields!CompInfo_Picture.Value) 6. Select Report, Report Properties. 7. On the Code tab, add the following custom variable and functions to the Report. Shared PictureData as Object Public Function GetPicture() as Object Return PictureData End Function Public Function SetPicture(NewData as Object) if NewData>"" PictureData = NewData end if End Function
8. 9. 10. 11. 12. 13. 14. 15. 16.
3-26
Close the Report Properties window. Add an Image control to the Page Header section. In the Properties window, set the Source property to Database. In the Properties window, set the MIME Type property to image/bmp. In the Properties window, set the Value property to: =Convert.FromBase64String(Code!GetPicture()) Add a textbox control to the Page Header. Attention: the textbox must be placed above the Image control added in step 9. In the Properties window, set the Hidden property to True. In the Properties window, set the Color property to Red. In the Properties window, set the Value property to: =Code!SetPicture(ReportItems!CompanyPicture.Value).
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Notice that this is an advanced way of using expressions. Simply stated, the following techniques are used: 1. The database picture, which appears in the dataset, is stored in a hidden textbox in the body section. A picture cannot be displayed in a textbox, so the picture must be converted to a text string. 2. At the top of the Page Header section, a second hidden textbox is displayed which retrieves the value from the first hidden textbox using the ReportItems collection and stores it in a custom variable PictureData (using the SetPicture() function). 3. The Image control retrieves the picture from the variable (using the GetPicture() custom function) and converts the string value back into a picture. When the report is run, the hidden textbox in the header, which is located above the image control, is rendered before the image control, causing the SetPicture() function to be executed before the GetPicture(). The previous procedure is used in a considerable number of reports, to retrieve data that is printed in the Page Header section.
Anatomy of the Sales Invoice Report In Microsoft Dynamics NAV the Sales Invoice Report (report 206) is used to print sales invoices. From a functional point of view this is not very extraordinary, but from a technical point of view the Sales Invoice report is rather difficult to understand. This lesson provides an overview of the anatomy of the Sales Invoice Report. Because the Sales Invoice Report is built similar to other reports in Microsoft Dynamics NAV, it is important to understand how it is designed. This lesson will focus on the RDLC report layout. The Classic report layout is covered in depth in the Microsoft Official Courseware C/SIDE Solution Development.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-27
Report Design in Microsoft Dynamics® NAV 2009 The Data Model Looking at the logical design for the Sales Invoice Report, you find the following data model:
FIGURE 3.5 THE DATA MODEL OF REPORT 206
The two primary tables used in creating a sales invoice are the Sales Invoice Header and the Sales Invoice Line tables. In this report, some supporting variables are used to access information from tables that do not fit into the data model. Supplemental tables, such as Payment Terms, Shipment Method, Salesperson/Purchaser and Company Information, are used to expand the code fields used in the invoice tables to more descriptive text. The Company Information table is used to retrieve information about the company that is preparing the invoice. The report also uses a virtual table: Integer. The Integer table is used for the logical loops that are run through during report execution.
The Triggers If you compare the report to the Microsoft Dynamics NAV 5.0 SP1 release and look at the triggers of the data items in the report, not much new code is added. In the next paragraphs, the code changes for each data item are explained.
CopyLoop - OnPreDataItem The CopyLoop data item is executed for each Sales Invoice Header. The function of this data item is to have multiple copies of the report printed in one report run. Although the CopyLoop is not the top-level data item in the report, it controls the printing of the entire report. All printed sections in the Classic report depend on this data item and are repeated for each copy loop. (The Sales Invoice Header data item is mainly only used for filtering and data retrieval purposes; it has no 3-28
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report printed sections.) If a sales invoice has more than one page, all pages are printed in the PageLoop cycle, which is subordinated to the CopyLoop cycle. If two copies of the report are to be printed, all pages of the invoice will be printed before the invoice is printed a second time. If multiple reports are to be printed, all copies of the first invoice will be printed before the next invoice is printed. Because the RoleTailored client supports only one body section, the layout of the Classic report cannot be built in Visual Studio Report Designer in the same way as it is designed in the Classic client. To have the pages of the invoice grouped by invoice header, a new integer variable OutputNo is introduced. The variable is used to control the number of copies of a report and is used to group the pages and copies of the report. To make the variable available in the dataset, it is added in a hidden textbox to the sections of the Classic report. In the OnPreDataItem trigger of the CopyLoop data item, a piece of code is added which initializes a new Integer variable, OutputNo. IF ISSERVICETIER THEN OutputNo := 1;
The ISSERVICETIER statement is used to distinguish code for the RoleTailored client from code that is executed for the Classic report. In this case, the variable will only be initialized for the RDLC report layout.
CopyLoop - OnAfterGetRecord In the OnAfterGetRecord trigger, two pieces of code using the ISSERVICETIER function are added. IF Number > 1 THEN BEGIN CopyText := Text003; IF ISSERVICETIER THEN OutputNo += 1; END; CurrReport.PAGENO := 1; IF ISSERVICETIER THEN BEGIN TotalSubTotal := 0; TotalInvoiceDiscountAmount := 0; TotalAmount := 0; TotalAmountVAT := 0; TotalAmountInclVAT := 0; TotalPaymentDiscountOnVAT := 0; END
The first piece of code is used to increment the OutputNo value for each copy of the report. For the first copy of the report, OutputNo will equal one, for the second copy, OutputNo will be two, and so on. The OutputNo value is used to group the data in the report. All pages will appear in the same order as in the Classic client.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-29
Report Design in Microsoft Dynamics® NAV 2009 The second piece of code is used to reset a number of variables to zero for each copy of the report. The variables are used to display the different subtotals in the RDLC report layout. In the Classic client, the different totals are calculated using the CREATETOTALS statement. CREATETOTALS maintains group and grand totals for the specified variables or fields. To print the totals, you must place controls that have the variable(s) or field(s) that are the arguments of CREATETOTALS as their source expressions in the appropriate Footer or GroupFooter sections. In the Classic client, a number of footer sections are used to display the totals However, the different totals are calculated and stored internally in the Classic report and are by default not available in the RDLC report layout. To make the values available in the dataset, they must be stored in additional variables. In addition, the variables must be reset after each copy of the report. (In the Classic client, subtotals are automatically reset to zero.)
Sales Invoice Line - OnAfterGetRecord As already mentioned in the previous paragraph, the subtotals of the Classic report are calculated and stored in extra variables for the RDLC report layout. To calculate the totals, the following piece of code is added: IF ISSERVICETIER THEN BEGIN TotalSubTotal +="Line Amount"; TotalInvoiceDiscountAmount -="Inv. Discount Amount"; TotalAmount += Amount; TotalAmountVAT +="Amount Including VAT" - Amount; TotalAmountInclVAT +="Amount Including VAT"; TotalPaymentDiscountOnVAT += -("Line Amount" - "Inv. Discount Amount" - "Amount Including VAT"); END
This code is used to calculate the subtotals for the RDLC report layout only. The totals are added as invisible controls to the footer sections in the Classic report and converted to dataset fields.
3-30
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The RDLC design Look at the RDLC layout of the report. There are many controls and tables both in the header and in the body section.
FIGURE 3.6 RDLC REPORT LAYOUT OF THE SALES INVOICE
Some of the controls have red text and are invisible controls. The Hidden property in the Visibility property collection is set to True.
The Body Section In the top left corner of the Body section you see two hidden tables. The right table has three columns and contains the logo from the Company Information table. Each cell corresponds to a Picture control from the classic design. The picture is converted to text for it to be stored in a textbox, using the Convert.ToBase64String() function. The left table contains four columns. Each column contains specific information that is available through variables in the Classic report. The first column contains all fields for the customer's address. The second column includes information regarding the company address. The third column contains much information coming from the Company Information table. The fourth column contains all kinds of information related to the Sales Invoice Header: fields from the Sales
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-31
Report Design in Microsoft Dynamics® NAV 2009 Invoice Header (such as Due date), fields from the Salesperson/Purchaser table, and other elements. The following table shows the names and values of the four text boxes.
3-32
Name
Value Expression
CustAddr
=Fields!CustAddr_1_.Value + Chr(177) + Fields!CustAddr_2_.Value + Chr(177)+ Fields!CustAddr_3_.Value + Chr(177)+ Fields!CustAddr_4_.Value + Chr(177)+ Fields!CustAddr_5_.Value+Chr(177)+ Fields!CustAddr_6_.Value + Chr(177)+ Fields!CustAddr_7_.Value+Chr(177)+ Fields!CustAddr_8_.Value
CompanyAddr
=Fields!CompanyAddr_1_.Value + Chr(177) + Fields!CompanyAddr_2_.Value + Chr(177)+ Fields!CompanyAddr_3_.Value + Chr(177)+ Fields!CompanyAddr_4_.Value + Chr(177)+ Fields!CompanyAddr_5_.Value + Chr(177)+ Fields!CompanyAddr_6_.Value
CompanyInfo
=Fields!CompanyInfo__Phone_No__Caption.Value + Chr(177) + Fields!CompanyInfo__Phone_No__.Value + Chr(177) + Fields!CompanyInfo__Fax_No__Caption.Value + Chr(177) + Fields!CompanyInfo__Fax_No__.Value + Chr(177)+ Fields!CompanyInfo__VAT_Registration_No__Caption.V alue + Chr(177)+ Fields!CompanyInfo__VAT_Registration_No__.Value + Chr(177)+ Fields!CompanyInfo__Giro_No__Caption.Value + Chr(177)+ Fields!CompanyInfo__Giro_No__.Value + Chr(177)+ Fields!CompanyInfo__Bank_Name_Caption.Value + Chr(177)+ Fields!CompanyInfo__Bank_Name_.Value + Chr(177)+ Fields!CompanyInfo__Bank_Account_No__Caption.Value + Chr(177)+ Fields!CompanyInfo__Bank_Account_No__.Value
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Name
Value Expression
SalesHdrInfo
=Fields!Sales_Invoice_Header___Bill_to_Customer_No__ Caption.Value + Chr(177) +Fields!Sales_Invoice_Header___Bill_to_Customer_No__. Value + Chr(177) + Fields!VATNoText.Value + Chr(177) + Fields!Sales_Invoice_Header___VAT_Registration_No__. Value + Chr(177) + Fields!ReferenceText.Value + Chr(177) + Fields!Sales_Invoice_Header___Your_Reference_.Value + Chr(177) + Fields!Invoice_No_Caption.Value + Chr(177) + Fields!Sales_Invoice_Header___No__.Value + Chr(177) + Fields!OrderNoText.Value + Chr(177) + Fields!Sales_Invoice_Header___Order_No__.Value + Chr(177) + Fields!Sales_Invoice_Header___Posting_Date_Caption.Val ue + Chr(177) + Fields!Sales_Invoice_Header___Posting_Date_.Value + Chr(177) + Fields!Sales_Invoice_Header___Due_Date_Caption.Value + Chr(177) + Fields!Sales_Invoice_Header___Due_Date_.Value + Chr(177) + Fields!Sales_Invoice_Header___Prices_Including_VAT_C aption.Value + Chr(177) + Cstr(Fields!PricesInclVAT_YesNo.Value) + Chr(177) + First(Fields!FORMAT__Sales_Invoice_Header___Docume nt_Date__0_4_.Value) + Chr(177) + First(Fields!STRSUBSTNO_DocumentCaption_CopyText _.Value) + Chr(177) + Fields!SalesPersonText.Value + Chr(177) + Fields!SalesPurchPerson_Name.Value + Chr(177) + Fields!PageCaption.Value
In each expression, Chr(177) is used to separate the different data parts in each group. When the GetData() function is called, data in the group is split by using the Split function with Chr(177) as a separator. This kind of hidden information is placed in a table header row and not in a table detail row (because it is only needed once). Using a table detail row can impact report execution time. Further down in the Body section you see a number of tables that are used to display the various blocks of information that need to be included in the report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-33
Report Design in Microsoft Dynamics® NAV 2009 The table3 table contains information regarding the dimensions of the sales invoice header. The table is only printed when the Show Internal Information option is checked in the request options page. In the DimensionLoop of the report, all dimensions for the posted sales invoice header will be run through and stored in a text variable. The first header row in the table will be printed the first time the DimensionLoop cycle is run through. The second header row will be printed in all other loops. The Table_Lines table contains all details of the Sales Invoice Line table. The table has one header row, two group header rows, two detail rows and thirteen group footer rows. The header row contains the field captions. The two group header rows display the details of the Sales Invoice Line. The Visibility property for these rows is set in a way that the first row header is printed for sales invoice lines where the Type field is and the second header is printed for the other sales invoice lines. The two detail rows contain details regarding the posted shipments and the dimensions for the sales invoice line. Again visibility options are defined to show or hide the rows when necessary. The thirteen group footer rows are used to show the different subtotals. The table properties are set to repeat the table header row on each page. The Table_VAT table contains all VAT related specifications from the VATCounter data item. The first two (header) rows of the table contain captions. The detail row shows all details for the VATCounter data item. The table footer row displays the totals for the VAT Amount Specifications. The Table_VATLCY table contains all VAT related specifications from the VATCounterLCY data item. The first three (header) rows of the table contain captions and information about the exchange rates of the amounts. The detail row shows all details for the VATCounter data item. The table footer row displays the totals for the VAT Amount Specifications in local currency. The Table_PaymentShipment contains two detail rows showing the description for the Payment Terms and Shipment Method of the Sales Invoice Header. The table contains a more descriptive text than the corresponding Payment Terms Code and Shipment Method Code. Finally, the Table_ShipToAddress table contains shipping information for the sales invoice header. It contains two header rows (with a table caption and some customer information) and nine detail rows (including the Ship-To Address information).
The List Ccontrol All tables in the body section are placed inside a list control. A list is a data region that presents data arranged in a freeform fashion. You can arrange report items to create a form with text boxes, images, and other data regions placed anywhere within the list. The list is considered as a big form and will be printed as such. When deleting a list control, all controls that are placed inside a list control will be deleted too.
3-34
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The Header Section At the top of the Header section, there are seven hidden controls. The purpose of these seven controls is to retrieve information that is stored somewhere (hidden) in the Body section and to load it into custom variables. To do this, the text boxes use the custom functions SetData() and SetPicture() that are defined in the report. The SetData() function has two parameters. The first parameter, NewData, is the data value that is stored in the custom variable. The second parameter, Group, is an integer that refers to the custom data variable that is used. Public Function SetData(NewData as Object,Group as integer) If Group = 1 and NewData > "" Then Data1 = NewData End If If Group = 2 and NewData > "" Then Data2 = NewData End If If Group = 3 and NewData > "" Then Data3 = NewData End If If Group = 4 and NewData > "" Then Data4 = NewData End If End Function
The SetPicture() function has the same syntax and the same purpose. It retrieves the hidden pictures from the body section and loads them into the shared PictureData variables. The custom data variables are defined as shared variables of the type Object. Shared Shared Shared Shared ... Shared Shared Shared
Data1 Data2 Data3 Data4
as as as as
Object Object Object Object
PictureData1 as Object PictureData2 as Object PictureData3 as Object
An object is a more complex data type. Unlike simple data types (such as integer, string, Boolean, and so on), it can contain more complex data values, such as data that can be broken down into smaller pieces. In this case, the data variables can be considered as arrays: they contain multiple values. Shared means they are available throughout the entire report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-35
Report Design in Microsoft Dynamics® NAV 2009 When the report is run and the header section is rendered, it starts with the textboxes at the top. As a result of evaluating the expression that is set in the Value property of the textboxes, the data is retrieved from the hidden textboxes in the Body section and loaded into the custom variables. As a first parameter, the function takes an element from the ReportItems collection. After the hidden textboxes, the three image controls are rendered. The Value property of the Image controls is set to: =Convert.FromBase64String(Code.GetPicture(x)) where x represents an integer between 1 and 3 (both included)). The function GetPicture() retrieves the value of the PictureData custom variable and converts it back from text to picture. Now, the other text boxes in the page header will be rendered. Public Function GetData(Num as Integer, Group as integer) as Object if Group = 1 then Return Cstr(Choose(Num, Split(Cstr(Data1),Chr(177)))) End If if Group = 2 then Return Cstr(Choose(Num, Split(Cstr(Data2),Chr(177)))) End If if Group = 3 then Return Cstr(Choose(Num, Split(Cstr(Data3),Chr(177)))) End If if Group = 4 then Return Cstr(Choose(Num, Split(Cstr(Data4),Chr(177)))) End If End Function
Each of these textboxes is using the GetData() function, which has two parameters. The first parameter, Num, is an integer value that refers to the element in the custom data variable. The second parameter, Group, refers to the data variable that is used. There are four groups: one for the customer address, one for the shipping address, one for the company information and one for the sales invoice header. In the GetData() function, the data is extracted from the variable using the Choose() and Split() functions. The Split() function takes a string argument, divides the string into elements by using the space character as the delimiter, and returns a string array. It has two parameters: the string to split (CStr(Data1)) and the space delimiter (Chr(177)). The CStr() function is used to convert the custom variable to string. The string array is then passed as a second parameter to the Choose() function.
3-36
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report The Choose() function selects and returns a value from a list of arguments. The first parameter, Num, determines which element will be retrieved from the string array. For example: =Code.GetData(1,2)
will return element 1 in the custom variable Data2. This corresponds to the Company Name (the first element in the CompanyAddr array in the Classic report). After the header is rendered, the Body section will be rendered.
Print Header Information on Multiple Pages Sometimes you must include hidden fields in the body of the report to successfully create a client report definition (RDLC) report layout. Typically, you add hidden fields to the table in the body section of the RDLC report layout. However, if there is more than one table in the report, the header information is not displayed on pages that display the subsequent tables. Instead, it is only displayed on the page with the first table. For reports such as document reports (invoices, credit memos) that have multiple tables and require header information on each page, you must ensure to: •
Create hidden text boxes in one table to get the data.
•
Create a function to save the data, which you call from one or more hidden fields in the header section.
•
Create a function to retrieve the data, which you call from one or more displayed text boxes in the header section.
The same applies to tables that span multiple pages. For information to be passed from one page to the next, you might include it as a hidden column in the data region control that spans multiple pages. An alternative solution is to include the information in a hidden textbox in the body section (outside the data region control), and make the textbox travel along with the data region control. To do this, select the textbox properties, check the Repeat report item with data region on every page and specify the data region control that can span multiple pages. Remember that headers and footers in client report definition (RDLC) report layouts have the following limitations: •
Expressions in a header or footer can refer to only one report item.
•
Data-bound fields in a header or footer will give an error. You must put the data-bound field in a text box in the body section, and either save the data to a global variable, or use ReportItem!.
•
There can be only one header, one body, and one footer in a report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-37
Report Design in Microsoft Dynamics® NAV 2009 When you create a layout suggestion, data-bound fields in the header are automatically moved to hidden fields in the body of the report. However, in some cases, it might be necessary to create additional hidden text boxes in the body section of a report so that in the new layout, you can reference that report item in the header or footer.
The Number of Copies Option For document type reports, often the request form displays an option for the number of copies to print. In a client report definition (RDLC) report layout, a copy is the same as a new document that must start on a new page. You must add code to set and update the copy number, group the data based on the copy number, and then specify a page break at the end of the group.
To Add Code to the Report for the Number of Copies Previously, this chapter described the code that is added to the data item trigger in the Classic report that is required to initialize and increment the copy number. Also mentioned earlier is that the OutputNo must be added to the sections of the report.
To Group Data Based on Copy Number 1. In the Classic client, on the View menu, click Layout. 2. In Microsoft Visual Studio, in the report.rdlc file, right-click the row to group on, and then click Edit Group. 3. In the Grouping and Sorting Properties window, on the General tab, under Group on, select the next blank line to add a grouping, and then select =Fields!OutputNo.Value from the drop-down list. 4. In the Grouping and Sorting Properties window, click the Sorting tab. 5. Select a blank line, and then select =Fields!OutputNo.Value from the drop-down list.
To Specify the Page Break To specify the page break for the report, proceed as follows: 1. Right-click the List control and select Properties. 2. On the General tab, click the Edit Details Group button. 3. In the Grouping and Sorting Properties window, check the Page break at end option. 4. Click OK to close the Grouping and Sorting Properties window. 5. Click OK to close the List Properties window.
3-38
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Reset Page Numbers On some reports, you might want to group sets of data together and reset the page number after each group. For example, in the standard application, report 206, Sales Invoice, displays sales invoices that are grouped by sales invoice number. To reset the page number to one for each group of data, you must modify code on the client report definition (RDLC) report layout.
To Reset Page Numbers: 1. In the Classic client, on the Tools menu, click Object Designer. 2. In Object Designer, click Report, select a report to modify, and then click Design. 3. On the View menu, click Layout. 4. In Microsoft Visual Studio, in the Report.rdlc file, on the Report menu, select Report Properties. 5. In the Report Properties window, select the Code tab. 6. Add the following code in the Custom code text box:
REM Reset Page Number: Shared offset As Integer Shared newPage As Object Shared currentgroup1 As Object Shared currentgroup2 As Object Shared currentgroup3 As Object Public Function GetGroupPageNumber(ByVal NewPage As Boolean, ByVal pagenumber As Integer) As Object If NewPage Then offset = pagenumber - 1 End If Return pagenumber - offset End Function Public Function IsNewPage(ByVal group1 As Object, ByVal group2 As Object, ByVal group3 As Object) As Boolean newPage = False If Not (group1 = currentgroup1) Then newPage = True currentgroup1 = group1 Else If Not (group2 = currentgroup2) Then newPage = True currentgroup2 = group2 Else If Not (group3 = currentgroup3) Then newPage = True
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-39
Report Design in Microsoft Dynamics® NAV 2009 currentgroup3 = group3 End If End If End If Return newPage End Function
7. In Visual Studio, in the Report.rdlc file, right-click the textbox in the header that displays the page number, and then select Expression. 8. In the Expression window, enter the following expression: =Code.GetGroupPageNumber(ReportItems!NewPage.Value,Globals !PageNumber) 9. In the Body section of the layout, create a new textbox called NewPage. 10. Right-click the NewPage textbox created in step 8 and then select Properties. 11. In the Properties window, on the General tab, enter the following in the Value field. =Code.IsNewPage(Fields![,,]) For example, if you are grouping by document type, then grouping field1 is Document_Type.Value. To use more than three groupings, you can modify the code in the IsNewPage function. To use less than three groupings, you can either modify the code in the IsNewPage function or use a static value for one or more of the function parameters.
Summary This chapter described how to create and use expressions in a report for different purposes (formatting, visibility options, data retrieval and grouping). The chapter also described how to add custom code and custom variables to a report. Lastly, it provided a better understanding of how the sales invoice report works.
3-40
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report
Test Your Knowledge 1. Which decision functions can be used in expressions in Visual Studio Report Designer? (Select all that apply) ( ) Iif() ( ) Switch() ( ) Case() ( ) Select Case() 2. Can nested IiF() statements be used? ( ) No. ( ) Yes, but only up to two levels ( ) Yes ( ) None of the answers is correct. 3. Which function is used to identify the row number in a data region control? ( ) Row ( ) RowNo ( ) RowNumber ( ) NoRow 4. Which expression returns the name of the Windows user (without the domain name) that is running an RDLC report? ( ) =Right(USERID, Len(USERID)) ( ) =Right(User!UserID, Len(User!UserID) - InStr(User!UserID, "\")) ( ) =Right(Report!UserID, Len(Report!UserID) - InStr(Report!UserID, "\")) ( ) This is not possible as the RoleTailored Client does not use Windows accounts. 5. What is not true about expressions? ( ) Expressions can be used for sorting. ( ) Expressions can be used to determine the visibility of controls. ( ) Expressions can be used for formatting. ( ) Expressions cannot be used to insert page breaks in a report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-41
Report Design in Microsoft Dynamics® NAV 2009 6. What is true about Custom Code in a report? (Select all that apply) ( ) Functions that are defined in the Classic report are automatically added to the RDLC report layout when using the Create Layout Suggestion option. ( ) Custom Code is available in the Expression window using the Code collection. ( ) Custom Code can be added in various places in Visual Studio Report Designer. ( ) Custom Code must be added using Visual Basic syntax.
3-42
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report
Lab 3.1a - Adding Conditional Formatting to a Report - I In this lab you will further design the Item Catalog created in Lab 2.4. You will use expressions to change visibility options and formatting. Scenario The RDLC report layout of the Item Catalog is already designed. Now it is time to further fine-tune the report. You need to add conditional formatting to make the report more user-friendly: •
Table headers need to be printed with a LightGrey background.
•
The Picture column needs to have a caption.
•
Rows need to be printed with alternating colors.
•
Negative inventory values need to be displayed in bold and in red.
•
The Image control needs to be hidden automatically when an item has no picture.
The result needs to look like this:
FIGURE 3.7 THE CRONUS ITEM CATALOG
In Lab 3.1b you will use expressions to add other functionality.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-43
Report Design in Microsoft Dynamics® NAV 2009 Challenge Yourself! Change the Item Catalog built in Lab 2.4, so that the column headers are printed with a LightGrey background and so that it uses alternating background colors (PaleGreen and Transparent) for the items. Ensure that negative inventory totals are displayed in bold and in red. Change the report so that the visibility of the Picture field is no longer able to be toggled by the Item No. Instead, ensure the image control is hidden automatically for items that do not have a picture. Next, change the report so that the column captions are printed on every page. In Lab 3.1b additional formatting will be added.
Need a Little Help? 1. 2. 3. 4. 5. 6.
Change the Background Color for the Header Row. Change the Background Colors for the Detail Row. Change the Color of Negative Inventory Values to Red. Change the Visibility Option for the Picture Field. Repeat the Column Captions on Each Page. Run the Report.
Step by Step In this lab, the following steps need to be executed:
Change the Background Color for the Header Row 1. Open report 123456704 in Visual Studio Report Designer. 2. On the Header row of the table control, select the cell above the Image control. 3. In the Properties window, set the Value property to Picture. 4. In the header row of the table control, select the textboxes containing the No. Description, Base Unit of Measure, Unit Price, Inventory and Picture field captions. 5. In the Properties window, set the BackgroundColor property to LightGrey.
Change the Background Colors for the Detail Row 1. On the detail row of the table control, select the textboxes containing the No. Description, Base Unit of Measure, Unit Price and Inventory fields. 2. In the Properties window, in the BackgroundColor property, select <Expression...>.
3-44
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report 3. In the Expression window, enter the following expression: =Iif(RowNumber(Nothing) Mod 2 = 0, "PaleGreen", "Transparent") 4. Click OK to close the Expression window.
Change the Color of Negative Inventory Values to Red 1. On the detail row, select the textbox containing the Inventory field. 2. In the Properties window, in the Color property, select <Expression...>. 3. In the Expression window, enter the following expression: =Iif(Fields!Item_Inventory.Value < 0, "Red", "Black"). 4. Click OK to close the Expression window. 5. In the Properties window, expand the Font property collection. 6. In the FontWeight property, select <Expression...>. 7. In the Expression window, enter the following expression: =Iif(Fields!Me.Value < 0, "Bold", "Normal"). 8. Click OK to close the Expression window.
Change the Visibility Option for the Picture Field 1. 2. 3. 4. 5.
On the detail row, select the Image control. In the Properties window, expand the Visibility property collection. Clear the ToggleItem property. In the Hidden property, select <Expression...>. In the Expression window, enter the following expression: =Iif(Len(Convert.ToBase64String(Fields!Item_Item_Picture.value)) > 0, False, True). 6. Click OK to close the Expression window.
Repeat the Column Captions on Each Page 1. Right-click any cell in the table and choose "Select 'table1'." 2. Right-click the shaded border of the selected table and choose Properties. The Table Properties window will appear. 3. On the General tab, check the Repeat header rows on each page option. 4. Click OK to close the Table Properties window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-45
Report Design in Microsoft Dynamics® NAV 2009 Run the Report 1. 2. 3. 4.
3-46
Exit Visual Studio. Save and import the RDLC changes. Save and compile the report in the Report Designer. Run the report from the Start, Run menu.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report
Lab 3.1b - Adding Conditional Formatting to a Report - II In this lab you will further design the Item Catalog created in Lab 3.1. You will use expressions to change visibility options and formatting. Furthermore, you will introduce a request options page and work with multiple headers and detail rows. Scenario The Item Catalog report is used by two types of users: first it is used by the salespeople of CRONUS International Ltd. during the daily order process. Therefore, detailed inventory information and pictures are included. Secondly, a copy of the report is sometimes handed out to customers. In that case, less detailed inventory information is required. To support both requests with one and the same report, you need to change the report so that the user has the option to print the inventory as a numeric value or as an icon indicating the inventory status: •
Inventory > 0: show a green checkmark.
•
Inventory = 0: show a blue question mark.
•
Inventory < 0: display a red cross.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-47
Report Design in Microsoft Dynamics® NAV 2009 The result needs to look like this:
FIGURE 3.8 THE CRONUS ITEM CATALOG
Challenge Yourself! Change the report from Lab 3.1a so that you can either have the exact inventory displayed (as a numeric value) or an embedded icon showing the inventory status: •
Inventory > 0: show a green checkmark.
•
Inventory = 0: show a blue question mark.
•
Inventory < 0: display a red cross.
The icons are provided on the training DVD. When printing the report, the user gets a "Graphic Inventory" option, which determines what will be printed. When printing the "Graphic Inventory", no pictures are printed; the background colors alternate between LightBlue and Transparent.
Need a Little Help? 1. 2. 3. 4. 5. 6. 7.
3-48
Add a Boolean Variable to the Classic Design. Change the Classic Section Design. Design the Request Options Page. Embed the Images in the Report. Add an Additional Table Header Row. Add an Additional Table Detail Row. Adjust the New Table Detail Row.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report 8. 9. 10. 11. 12. 13.
Add an Image Control for the Inventory field. Set the Value Property of the Inventory field. Change the Visibility of the Table Header Row. Change the Visibility of the Table Detail Row. Change the Alternating Colors for the Table Detail Row. Run the Report.
Step by Step In this lab, the following steps need to be executed:
Add a Boolean Variable to the Classic Design 1. Open the Classic report 123456704 in the Object Designer. 2. Select View, C/AL Globals. 3. On the Variables tab, on a blank line, enter GraphicalInventory in the Name column. Select Boolean in the DataType column. 4. Click OK to close the C/AL Globals window. 5. Save and compile the Classic report.
Change the Classic Section Design 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
Open the Classic report in the Object Designer. Select View, Sections. In the Toolbox window, select the Textbox control. Click the Item Header section to insert a new textbox in the report. Right-click the new textbox and select Properties. In the Properties window, set the SourceExpr property to GraphicalInventory. In the Properties window, set the ForeColor property to 255. In the Properties window, set the Visible property to No. Close the Section Designer. Save and compile the Classic report.
Design the Request Options Page 1. Open the Classic report in the Object Designer. 2. Select View, Request Page.The Request Options Page Designer will be opened. As the report did not contain a request page yet, the window is blank. 3. On the first blank line, enter My Request Page in the Caption column.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-49
Report Design in Microsoft Dynamics® NAV 2009 4. On the same line, select Container in the Type and ContentArea in the SubType column. 5. On the second line, enter Options in the Caption column. In the Type and SubType column, select Group. 6. On the third line, enter Graphical Inventory in the Caption column. Choose Field n the Type column. In the SourceExpr column, enter GraphicalInventory. 7. Click the Close button in the top right corner to close the Request Options Page Designer. 8. Save and compile the Classic report.
Embed the Images in the Report 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
Open the report in Visual Studio Report Designer. Select Report, Embedded Images. In the Embedded Images window, click the New Image button. Browse to the folder containing select image058.gif. Click Open to import the image. In the Name column, change the name of the image to InvGreen. In the Embedded Images window, click the New Image button. Browse to the folder containing image174.gif. Click Open to import the image. In the Name column, change the name of the image to InvRed. In the Embedded Images window, click the New Image button. Browse to the folder containing image714.gif. Click Open to import the image. In the Name column, change the name of the image to InvBlue. Click OK to close the Embedded Images window.
Add an Additional Table Header Row 1. Click the cell containing the Item No. caption in the table header row. 2. Right-click the row handle for the table header row and select Insert Row Below. 3. In the first header row, select the first five cells and press Ctrl+C to copy the selection to the clipboard.. 4. Select the first cell on the newly added header row and press Ctrl+V. 5. Select the sixth cell on the header row. 6. In the Properties window, set the BackgroundColor property to Transaparent.
3-50
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Add an Additional Table Detail Row 1. Click a cell in the table detail row. 2. Right-click the row handle for the table detail row and select Copy. 3. Right-click the row handle for the table detail row again and select Paste. The table detail row will be duplicated.
Adjust the New Table Detail Row 1. Select the cell containing the image control on the newly added table detail row. 2. Delete the Image control. 3. Select the cell containing the Inventory field on the newly added table detail row. 4. Press Delete to clear the table cell.
Add an Image Control for the Inventory field 1. In the Toolbox window, select the Image control. 2. Drag it to the Inventory column on the second detail row. 3. In the Properties window, set the Source property to Embedded.
Set the Value Property of the Inventory field 1. Select the newly added Image control. 2. In the Properties window, set the Value property to the following expression: =Switch(Fields!Item_Inventory.Value < 0, "InvRed", Fields!Item_Inventory.Value = 0, "InvBlue", Fields!Item_Inventory.Value > 0, "InvGreen")
Change the Visibility of the Table Header Row 1. Click the cell containing the Item No. caption in the first table header row (the row including the Picture caption). The table row handle will now be displayed. 2. Click the row handle for the first table header row to select the entire table row. 3. In the Properties window, expand the Visibility property collection. 4. In the Hidden property, select <Expression...>. 5. In the Expression window, enter the following expression: =Iif(Fields!GraphicalInventory.Value = 0, False, True). 6. Click OK to close the Expression window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-51
Report Design in Microsoft Dynamics® NAV 2009 7. Click the cell containing the Item No. caption in the second table header row (the row that does not include the Picture caption). The table row handle will now be displayed. 8. Click the row handle for the second table header row to select the entire table row. 9. In the Properties window, expand the Visibility property collection. 10. In the Hidden property, select <Expression...>. 11. In the Expression window, enter the following expression: =Iif(Fields!GraphicalInventory.Value = 0, True, False). 12. Click OK to close the Expression window.
Change the Visibility of the Table Detail Row 1. Click the cell containing the Item No. field in the first table detail row. The table row handle will now be displayed. 2. Click the row handle for the first table detail row to select the entire table row. 3. In the Properties window, expand the Visibility property collection. 4. In the Hidden property, select <Expression...>. 5. In the Expression window, enter the following expression: =Iif(Fields!GraphicalInventory.Value = 0, false, true). 6. Click OK to close the Expression window. 7. Click the cell containing the Item No. in the second table detail row (the row that does not include the Picture field). The table row handle will now be displayed. 8. Click the row handle for the second table detail row to select the entire table row. 9. In the Properties window, expand the Visibility property collection. 10. In the Hidden property, select <Expression...>. 11. In the Expression window, enter the following expression: =Iif(Fields!GraphicalInventory.Value = 0, true, false). 12. Click OK to close the Expression window.
Change the Alternating Colors for the Table Detail Row 1. On the second detail row of the table control, select the textboxes containing the No. Description, Base Unit of Measure and Unit Price fields. 2. In the Properties window, in the BackgroundColor property, select <Expression...>. 3. In the Expression window, enter the following expression: =Iif(RowNumber(Nothing) Mod 2 = 0, "LightBlue", "Transparent"). 4. Click OK to close the Expression window.
3-52
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Run the Report 1. 2. 3. 4.
Exit Visual Studio. Save and import the RDLC changes. Save and compile the report in the Report Designer. Run the report from the Start, Run menu.
The Request Page of the report now shows an option called "Graphical Inventory". If you check the option, the result looks like the figure at the beginning of the lab.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-53
Report Design in Microsoft Dynamics® NAV 2009
Lab 3.2 - Using Custom Code in the Visual Studio Report Designer In this lab, you will use custom code to get the report finished. You will add controls to the body section and use the information in the header section. In addition, you will replace the embedded company logo by the company logo stored in the Microsoft Dynamics NAV database. Scenario In Lab 3.1b you introduced the Graphical Inventory option, to solve multiple end-user requests with one and the same report. You have created multiple header and detail rows that are printed depending on the selected option. As a side-effect of this, you notice that when printing the report with Graphical Inventory information, the company information in the header section is suddenly missing. In addition, you will replace the embedded company logo by the picture that is stored in the Microsoft Dynamics NAV database. You will solve these issues using custom code and variables.
Challenge Yourself! In this lab you will replace the embedded company logo by the company logo that is stored in the Company Information table. In addition, you will use custom functions to load the company information from the Body section and retrieve it in the Header section. Hidden controls need to be added to the Body and Page Header sections. Also, you will add the report execution time (as a long date), the current page number and the total number of pages to the report.
Need a Little Help? 1. 2. 3. 4. 5. 6. 7. 8.
Add Custom Code to the Report. Delete the Embedded Company Logo from the Report. Delete the Hidden Table Columns in the Body Section. Add a Hidden Table Control to the Body Section. Rearrange the Existing Controls in the Header Section. Add a Hidden Control for the Company Logo to the Header Section. Add the Database Picture to the Page Header Section. Add a Hidden Textbox Control for the Company Information to the Page Header Section. 9. Change the Controls in the Header Section to use the Custom Code. 10. Add the Report Execution Time, the Page Number and the Total Number of Pages to the Header Section. 11. Run the report.
3-54
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Step by Step In this lab, the following steps need to be executed:
Add Custom Code to the Report 1. Open report 123456704 in Visual Studio Report Designer. 2. Select Report, Report Properties. 3. On the Code tab, add the following custom functions and variables:
Shared CompData as Object Shared PictureData as Object Public Function SetData(NewData as Object, Group as integer) If Group = 1 and NewData > "" Then CompData = NewData End If End Function Public Function SetPicture(NewData as Object) If NewData > "" Then PictureData = NewData End If End Function Public Function GetData(Num as Integer,Group as integer) if Group = 1 then Return Cstr(Choose(Num, Split(Cstr(CompData),Chr(177)))) End If End Function Public Function GetPicture Return PictureData End Function
4. Click OK to close the Report Properties window.
Delete the Embedded Company Logo from the Report 1. Select Report, Embedded Images. 2. Select the Cronus Company logo, and click the Delete button to remove the picture.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-55
Report Design in Microsoft Dynamics® NAV 2009 Delete the Hidden Table Columns in the Body Section 1. In the body section, select the six hidden columns in the table control by clicking the table column handles. 2. Press Delete to delete the columns.
Add a Hidden Table Control to the Body Section 1. In the Toolbox window select the Table control, and drag it to the body section. 2. Remove the Table Detail row, the Table Footer row and the third column. 3. Select the first cell on the header row of the new table. 4. In the Properties window, set the Name property to CompInfoArray. 5. In the Properties window, set the Color property to Red. 6. In the Properties window, set the Value property to the following expression: =Fields!CompInfo_Name.Value & Chr(177) & Fields!CompInfo_Address.Value & Chr(177) & Fields!CompInfo__Post_Code_.Value & Chr(177) & Fields!CompInfo_City.Value & Chr(177) & Fields!CompInfo__Country_Region_Code_.Value & Chr(177) & Fields!CompInfo__VAT_Registration_No__.Value. 7. Select the second cell on the header row of the new table. 8. In the Properties window, set the Name property to CompLogoArray. 9. In the Properties window, set the Color property to Red. 10. In the Properties window, set the Value property to the following expression: =Convert.ToBase64String(Fields!CompInfo_Picture.Value). 11. Right-click one of the two cells and choose "Select 'table2'." 12. In the Properties window, set the Height property for the newly added table to 0.5. 13. In the Properties window, set the Hidden property to True. 14. Place the newly added table control above the "table1" control.
Rearrange the Existing Controls in the Header Section 1. Select all controls in the Page Header. 2. Press the Down arrow on the keyboard to move them two grid units down.
3-56
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report Add a Hidden Control for the Company Logo to the Header Section 1. In the Toolbox window, select the Textbox control and drag it to the top of the Page Header section, above all other existing controls. 2. In the Properties window, set the Hidden property to True. 3. In the Properties window, set the Color property to Red. 4. In the Properties window, set the Value property to the following expression: =Code.SetPicture(ReportItems!CompLogoArray.Value).
Add the Database Picture to the Page Header Section 1. Select the Image control in the page header section. 2. In the Properties window, set the Source property to Database. 3. In the Properties window, set the MIME Type property to image/bmp. 4. In the Properties window, set the Value property to the following expression: =Convert.FromBase64String(Code.GetPicture).
Add a Hidden Textbox Control for the Company Information to the Page Header Section 1. In the Toolbox window, select the Textbox control and drag it to the top of the Page Header section, above all other existing controls. 2. In the Properties window, set the Hidden property to True. 3. In the Properties window, set the Color property to Red. 4. In the Properties window, set the Value property to the following expression: =Code.SetData(ReportItems!CompInfoArray.Value, 1).
Change the Controls in the Header Section to use the Custom Code 1. In the Page Header section, select the textbox containing the Company Name (the first textbox under the Item Catalog textbox). 2. Change the Value property to =Code.Getdata(1,1). 3. Select the textbox containing the company address. 4. Change the Value property to =Code.Getdata(2,1). 5. Select the textbox containing the company post code. 6. Change the Value property to =Code.Getdata(3,1). 7. Select the textbox containing the company city.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-57
Report Design in Microsoft Dynamics® NAV 2009 8. 9. 10. 11. 12.
Change the Value property to =Code.Getdata(4,1). Select the textbox containing the company country/region code. Change the Value property to =Code.Getdata(5,1). Select the textbox containing the VAT Registration No. Change the Value property to =Code.Getdata(6,1).
Add the Report Execution Time, the Page Number and the Total Number of Pages to the Header Section 1. In the Toolbox window, select the Textbox control and drag it to the Page Header section, under the Image control. 2. In the Properties window, set the Value property to the following expression: ="Page " & Globals!PageNumber & "/" & Globals!TotalPages. 3. In the Toolbox window, select the Textbox control and drag it to the Page Header section, under the control created in step 1. 4. In the Properties window, set the Value property to the following expression: ="Date Printed: " & FormatDateTime(Globals!ExecutionTime, DateFormat.LongDate).
3-58
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report
Quick Interaction: Lessons Learned Take a moment and write down three Key Points you have learned from this chapter 1.
2.
3.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-59
Report Design in Microsoft Dynamics® NAV 2009
Solutions Test Your Knowledge 1. Which decision functions can be used in expressions in Visual Studio Report Designer? (Select all that apply) (√) Iif() (√) Switch() ( ) Case() ( ) Select Case() 2. Can nested IiF() statements be used? ( ) No. ( ) Yes, but only up to two levels (•) Yes ( ) None of the answers is correct. 3. Which function is used to identify the row number in a data region control? ( ) Row ( ) RowNo (•) RowNumber ( ) NoRow 4. Which expression returns the name of the Windows user (without the domain name) that is running an RDLC report? ( ) =Right(USERID, Len(USERID)) (•) =Right(User!UserID, Len(User!UserID) - InStr(User!UserID, "\")) ( ) =Right(Report!UserID, Len(Report!UserID) - InStr(Report!UserID, "\")) ( ) This is not possible as the RoleTailored Client does not use Windows accounts. 5. What is not true about expressions? ( ) Expressions can be used for sorting. ( ) Expressions can be used to determine the visibility of controls. ( ) Expressions can be used for formatting. (√) Expressions cannot be used to insert page breaks in a report.
3-60
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 3: Adding Code to a Report 6. What is true about Custom Code in a report? (Select all that apply) ( ) Functions that are defined in the Classic report are automatically added to the RDLC report layout when using the Create Layout Suggestion option. (√) Custom Code is available in the Expression window using the Code collection. ( ) Custom Code can be added in various places in Visual Studio Report Designer. (√) Custom Code must be added using Visual Basic syntax.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
3-61
Report Design in Microsoft Dynamics® NAV 2009
3-62
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations
CHAPTER 4: DESIGN CONSIDERATIONS Objectives The objectives are: •
Work with and understand how green bar and dashboard reports are built.
•
Work with and understand how reported layouts will be rendered when exporting to Excel or PDF.
•
Use some tips and tricks that can be useful when designing reports.
Introduction This chapter contains a more in-depth analysis of some advanced report features; such as dashboard reports and green bar reports. In addition, the chapter covers the different export possibilities and the rendering differences. The lessons require that you are familiar with the techniques taught in previous chapters.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-1
Report Design in Microsoft Dynamics® NAV 2009
Report Patterns and Recipes This lesson describes some of the typical challenges that you can encounter when developing reports. It shows how to combine the techniques from previous chapters to build more advanced reports.
Green Bar Matrix The term "green bar report" refers to a continuous paper form that was commonly used to print reports. The paper form had pre-printed white and light green areas to increase the readability. A green bar report actually is a report that prints rows or row groups with alternating background colors. In Chapter 3 is explained how you can define alternating background colors in table controls by setting the BackgroundColor property to an expression: =IIF(RowNumber("table1") Mod 2 = 0, "LimeGreen", "Transparent")
The expression uses the RowNumber() function and the Mod operator to calculate the correct background color. . If you want to create a green bar report using the Matrix control, the technique illustrated in Chapter 3 with the table control will not work. This is because every row in a matrix control must be a group. There is currently no GroupNumber() function on which to base a green bar calculation. In addition, some cells in the matrix may contain no data at all, which causes the group number calculation to be wrong for the empty cells. To work around this, you need to effectively calculate the group number in the row header and then use that value inside the data cells. This can be done either by using a small custom code function or by using the RunningValue function.
Method 1: The Custom Code Function The first method uses a small custom code function: Private bOddRow As Boolean Public Function AlternateColor(ByVal OddColor As String, ByVal EvenColor as String, ByVal Toggle As Boolean) As String If Toggle Then bOddRow = Not bOddRow End If If bOddRow Then Return OddColor Else Return EvenColor End If End Function
4-2
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations The function has three parameters: a color for odd rows, a color for even rows and a Boolean toggle parameter. The toggle parameter is used to indicate the start of a new row. Typically it will be set to True on the first cell and set to False on all other cells of the matrix row. With each new value that is printed in the column (after each row group), the Toggle parameter changes and the function returns another color. As a result, all cells in a row group will have the same color.
Method 2: The RunningValue() Function The second method uses the RunningValue() function: =IIF(RunningValue(Fields!Item__No__.Value,CountDistinct,Not hing) Mod 2, "PaleGreen", "White")
The RunningValue() function returns a running aggregate of the specified expression. The function has three parameters: a group expression, an aggregate function and a scope. The first parameter contains a group expression that you want to perform the aggregate function on. The expression cannot contain aggregate functions. The second parameter is the aggregate function that you want to apply to the group expression. This function cannot be RunningValue, RowNumber, or Aggregate. The third parameter, scope, refers to the dataset, grouping, or data region that contains the report items to which to apply the aggregate function. If a dataset is specified, the running value is not reset throughout the entire dataset. If a grouping is specified, the running value is reset when the group expression changes. If a data region is specified, the running value is reset for each new instance of the data region. In this second method, the result of the previous expression is stored in an invisible text box named Color. Next, the BackgroundColor property of the other cells will be set to refer to the invisible text box using the following expression: =ReportItems!Color.Value
The next demonstrations show how to use both methods.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-3
Report Design in Microsoft Dynamics® NAV 2009 Demonstration: Create a Green Bar Matrix with a Custom Code Function Ellen asks Mort to improve the readability of the report. Instead of having the item number and item name displayed on an orange background, she asks Mort to have the inventory amounts printed with alternating background colors. She also prefers a lighter pastel background color (PaleGreen). 1. Open report 123456701 in Visual Studio Report Designer. 2. Select Report, Report Properties. 3. On the Code tab, add the following code:
Private bOddRow As Boolean Public Function AlternateColor(ByVal OddColor As String, ByVal EvenColor as String, ByVal Toggle As Boolean) As String If Toggle Then bOddRow = Not bOddRow End If If bOddRow Then Return OddColor Else Return EvenColor End If End Function
4. Click OK to close the Report Properties window. 5. Select the cell containing the Customer No. and Customer Name fields. 6. In the Properties window, change the BackgroundColor property to the following expression: =Code.AlternateColor("White", "PaleGreen", True). 7. Select the cell containing the Inventory amounts. 8. In the Properties window, change the BackgroundColor property to the following expression: =Code.AlternateColor("White", "PaleGreen", False). 9. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it.
4-4
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations The result will look similar to this:
FIGURE 4.1 THE GREEN BAR MATRIX WITH THE CUSTOM CODE FUNCTION
In the previous figure, Mort notices that the item number and name are still printed in the same alternating background color. To solve this, he inserts a hidden column. 1. Open report 123456701 in Visual Studio Report Designer. 2. Right-click the cell containing the Customer No. and Customer Name fields and choose Select 'matrix1'. 3. Right-click the shaded border around the matrix control and choose Add Row Group. 4. In the Grouping and Sorting Properties window, set the Group on field to the same expression as the cell containing the Item No. and Name. In this case, select =Fields!Item__No__.Value. 5. Click OK to close the window. 6. Select the newly added row group cell. 7. In the Properties window, set the Hidden property to True. 8. In the Properties window, set the BackgroundColor property to the following expression: =Code.AlternateColor("White", "PaleGreen", True) 9. Select the cell containing the item number and item description.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-5
Report Design in Microsoft Dynamics® NAV 2009 10. In the Properties window, set the BackgroundColor property to Transparent. 11. Resize the column width to the minimal size. 12. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it. The result will look similar to this:
FIGURE 4.2 THE GREEN BAR MATRIX WITH A HIDDEN COLUMN
Demonstration: Create a Green Bar Matrix with RunningValue() In this demonstration you will use the RunningValue function to create a green bar matrix. 1. Open report 123456701 in Visual Studio Report Designer. 2. Select the row header cell (the cell containing the Customer No. and Customer Name fields). 3. Press Delete to clear the cell. 4. In the Toolbox window, select the Rectangle control. 5. Click the empty cell to insert a rectangle in the cell. 6. In the dataset, select the Item__No__ element and drag it inside the rectangle. 7. Right-click the Item__No__ text box and select Expression. 8. In the Expression window, enter the following expression: =Fields!Item__No__.Value & " ; " & Fields!Item_Description.Value.
4-6
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations 9. In the Toolbox window, select the Textbox control and drag it inside the rectangle. 10. In the Properties window, change the Name property of this text box to Color. 11. In the Properties window, change the Hidden property of the Color text box to True. 12. In the Properties window, change the Value property to the following expression: =IIF(RunningValue(Fields!Item__No__.Value,CountDistinct,Not hing) Mod 2, "White", "PaleGreen")
13. Select the rectangle control. 14. In the Properties window, change the BackgroundColor property to the following expression: =ReportItems!Color.Value. 15. Select the Item_Ledger_Entry_Quantity matrix cell. 16. In the Properties window, change the BackgroundColor property to the following expression: =ReportItems!Color.Value 17. Exit Visual Studio, import the RDLC report layout, save and compile the Classic report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-7
Report Design in Microsoft Dynamics® NAV 2009 The result will look similar to this:
FIGURE 4.3 THE GREEN BAR MATRIX WITH THE RUNNINGVALUE FUNCTION
If you want to define alternating background colors for the inventory matrix cells only, you can skip steps 13 and 14.
Dashboards Essentially, a dashboard report is a way to visually present critical data in summary form so that you can make quick and effective decisions, in much the same way that a car dashboard works. With the new reporting solution you can build your own dashboard reports to consolidate information from different areas in a single (report) interface. Also, extra features such as interactive analysis and views, charts and indicators can be added.
4-8
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations In many cases, a dashboard presents information from different tables by means of charts. Often, a dashboard is filtered so it only shows a subset of data. Instead of showing full details on all records in the different tables, it is used to show only the Top X for specific areas. The following figure shows a typical example of a sales dashboard:
FIGURE 4.4 CUSTOMER PERFORMANCE DASHBOARD
The dashboard contains two charts that give instant access to the top five (5) of the customers based on Total Sales and Balance Due (in local currency (LCY)). Furthermore it contains a chart with the total amount of outstanding orders in LCY. At the bottom of the report, a toggle button is used to show or hide the order details.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-9
Report Design in Microsoft Dynamics® NAV 2009 Dashboard Report Structure The basic structure of a dashboard report typically includes multiple data items without any indentation.
FIGURE 4.5 REPORT DESIGNER WINDOW
In some cases, indented data items can be added to perform additional data processing or grouping. The report will have the necessary sections with the corresponding fields so that the necessary fields are made available in Visual Studio Report Designer.
Dashboard Report Design Dashboard reports often use charts and images to present data. Adding a chart in a report can be done by inserting chart controls in the body section. When the chart control is added to the report, you can further design it. To do so, right-click the chart control and select Properties to open the Chart Properties window.
4-10
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations Chart Properties The Chart Properties window contains seven tabs allowing you to customize the chart.
FIGURE 4.6 CHART PROPERTIES WINDOW
On the General tab, you can select a chart type and subtype. In addition, you can specify a Title for the chart (and the format of this title). The Palette option allows you to choose a color palette for the chart. Also, you can define the Chart Area and the Plot Area styles. All information related to the underlying data can be found on the Data tab. It contains the name of the dataset, and the data values, categories and series of the chart. Data values, categories and series can be added to the chart by dragging fields from the dataset to the chart. (You can use the Data tab to manage them here.) The X Axis and Y Axis tabs contain options to format the data, labels, gridlines, and so on, that are shown on both the X axis (horizontal) and Y axis (vertical) of the chart. On the Legend tab, you can find an option to include a chart legend. Here you can change the layout, the position and the style of the legend. The 3D effects tab allows adding 3D effects to the chart. You can change horizontal and vertical rotation, transparency and shading.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-11
Report Design in Microsoft Dynamics® NAV 2009 Finally, on the Filters tab, you can add some general data region control filters to limit the information that is shown in the chart. For more information on formatting charts, refer to Get More Out of SQL Server Reporting Services Charts (http://msdn.microsoft.com/enus/library/aa964128.aspx).
The Top X Filter A filter can be added to a dataset, data region, or group when including or excluding specific values for calculations or display. Dataset filters cannot be added in Visual Studio Report Designer, as the dataset is provided by Microsoft Dynamics® NAV 2009. However data region and group filters can be added in Visual Studio Report Designer. Filters are applied at run time first on the dataset, and then on the data region, and then on the group, in top-down order for group hierarchies. In a table, matrix, or list, filters for row groups, column groups, and adjacent groups are applied independently. In a chart, filters for category groups and series groups are applied independently.
Setting Filters on a Data Region Control The following steps show how to add a filter to a data region control. 1. Open a report in Visual Studio Report Designer. 2. Right-click the data region on the design surface, and then click Properties to open the Properties window. 3. Click the Filters tab. This displays the current list of filter equations. By default, the list is empty. 4. Click an empty line. A new blank filter equation appears. 5. In Expression, type or select the expression for the field to filter. To edit the expression, click the expression (fx) button. 6. In the Operator box, select the operator that you want the filter to use to compare the values in the Expression box and the Value box. The operator you choose determines the number of values that are used from the next step. 7. In the Value box, type the expression or value against which you want the filter to evaluate the value in Expression. 8. Click OK.
Setting Filters on a Chart Category Group The following steps show how to add a filter to a chart category group. 1. Open a report in Visual Studio Report Designer. 2. Right-click the data region control and select Properties.
4-12
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations 3. 4. 5. 6. 7. 8. 9.
10. 11.
Click the Data tab. In the Category group field, select the group to filter. Click the Edit button. Click the Filters tab. This displays the current list of filter equations. By default, the list is empty. Click an empty line. A new blank filter equation appears. In Expression, type or select the expression for the field to filter. To edit the expression, click the expression (fx) button. In the Operator box, select the operator that you want the filter to use to compare the values in the Expression box and the Value box. The operator you choose determines the number of values that are used from the next step. In the Value box, type the expression or value against which you want the filter to evaluate the value in Expression. Click OK.
In the customer dashboard example, the filter is specified on category group level.
FIGURE 4.7 GROUPING AND SORTING PROPERTIES WINDOW
Setting Filters on a Chart Series Group The following steps show how to add a filter to a chart series group. 1. Open a report in Visual Studio Report Designer. 2. Right-click the data region control and select Properties. 3. Click the Data tab.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-13
Report Design in Microsoft Dynamics® NAV 2009 4. In the Series group field, select the group to filter. 5. Click the Edit button. 6. Click the Filters tab. This displays the current list of filter equations. By default, the list is empty. 7. Click an empty line. A new blank filter equation appears. 8. In Expression, type or select the expression for the field to filter. To edit the expression, click the expression (fx) button. 9. In the Operator box, select the operator that you want the filter to use to compare the values in the Expression box and the Value box. The operator you choose determines the number of values that are used from the next step. 10. In the Value box, type the expression or value against which you want the filter to evaluate the value in Expression. 11. Click OK. For examples of filter equations, refer to Filter Equation Examples (Reporting Services) (http://msdn.microsoft.com/en-us/library/cc627464.aspx).
The Order Details List The order details are displayed under the Outstanding Orders chart. By default all details are hidden. When clicking the Show Order Details label, the details will be shown. This is done by defining the Hidden and ToggleItem properties for the row cells.
4-14
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations Charts in Tables Instead of showing fields as numbers, you can insert charts in the table to display the values. Functions can be used, such as the Avg() function, to calculate specific values. You can then use the calculated value as a data value for each chart. At the same time, the "ALL" expression is used as a category group expression.
FIGURE 4.8 GROUPING AND SORTING PROPERTIES WINDOW
Report Rendering Considerations Reporting Services provides interactive reporting features that allow you to work with a report at run time. Not all of the report output formats support the full range of interactive features.
Excel Rendering Reporting Services supports the rendering of reports for Microsoft® Office Excel®. If you plan to render reports to Excel, be aware of some of the unique attributes of the Excel rendering extension. For example: •
Each page in the report becomes an Excel worksheet. Excel does not support the concept of page height and width, so only explicitly defined page breaks will occur.
•
Specifying worksheet names is not supported.
•
The rendering extension builds a tabular structure out of the report.
•
Excel does not support background images for individual cells.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-15
Report Design in Microsoft Dynamics® NAV 2009 •
Excel does not support nested containers other than lists.
•
Charts are rendered as pictures, not as Excel charts.
•
Rectangles are converted to groups of cells. If rectangles contain other items, the rectangle becomes a region of cells, and the border and background color of the rectangle are applied to the region of cells.
Using Tables Instead of Lists for Excel-specific Reports A table uses a fixed column width. This matches very well with the tabular format of Excel reports. The items in the report table will line up as you expect them to when rendered in Excel. In contrast, a list is a freeform style. Items in the list are positioned in the worksheet relative to their location in the report. This can lead to unexpected results. If your report uses a list, be sure to check the rendering to Excel to see if the results are acceptable. Even with tables, if you have a header that spans multiple columns in a report, the Excel rendering extension may need to merge cells or introduce new columns. This can affect the ability to sort and manipulate data in the Excel spreadsheet. If you are planning to render to Excel, try to ensure that the left or right edges of the report item line up to minimize cell merging.
Maximum Number of Pages in Long Reports To prevent Excel from generating an error, keep track of the number of pages in lengthy reports. Specifically, each page in a report becomes a worksheet in Excel. However, Excel can only support a maximum number of worksheets for each workbook, limited by available memory. If the report pages exceed that limit, Excel generates an error.
Color Differences in Rendering to Excel Excel supports a predefined set of colors. When you render a report, the Excel rendering extension maps the report colors to the best match in the natively supported colors in Excel.
4-16
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations PDF Rendering The portable document format (PDF) rendering extension creates reports that can be viewed with Adobe Acrobat readers. The rendering extension does not require Adobe software to render the report. However, PDF viewers such as Adobe Acrobat are required for viewing or printing a report in PDF format. When designing reports for PDF output, take into account the following considerations: •
Fonts are not embedded in the PDF reports.
•
Document maps are rendered as PDF bookmarks. In the document maps, the hierarchy is ignored. (All bookmarks will be on the same level.)
•
Specify page width, page height and margins of the PDF, if necessary.
•
The rendering extension creates PDF 1.3 files that are compatible with Adobe Acrobat 4.0 and later versions.
Installing the Appropriate Fonts on the Client Computer The PDF extension does not embed the fonts in the report. To view a report in the correct font, you need to ensure that all necessary fonts are installed on the client computer that is used to view the report. Otherwise, font substitution will most likely occur.
SAVEASEXCEL and SAVEASPDF In Microsoft Dynamics NAV 2009 two new C/AL functions have been introduced
SAVEASEXCEL The SAVEASEXCEL function can be used on the Report type and on Report variables to save a report as a Microsoft Office Excel file. It has the following syntax: [Ok :=] Report.SAVEASEXCEL(Number, FileName, [, Record]) [Ok :=] Report.SAVEASEXCEL(FileName)
When SAVEASEXCEL is called, the report is generated and saved to "FileName." A Saving to Excel window is displayed, which shows the progress of the process. If you click Cancel, the report will not be generated or saved as an Excel file. Also, the Request Form will not be shown. The return value informs you whether the report is saved successfully. If the report cannot be saved for a specific reason, the function will return False.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-17
Report Design in Microsoft Dynamics® NAV 2009 SAVEASPDF The SAVEASPDF function allows saving a report as a PDF file. It has the same syntax as the SAVEASEXCEL function. No PDF software is required to create PDF files. The SAVEASPDF and SAVEASEXCEL functions cannot be used on the Classic client. However the functions can be used in codeunits that are exposed as Web services. Other applications can call the Web services to have reports generated.
Useful Tips This lesson describes several techniques that can be useful when creating clientside reports in Visual Studio. It assumes that you are familiar with the content from the previous chapters.
CanGrow and CanShrink Whether you are designing reports for the Classic or the RoleTailored client, one of the challenges that typically arises is the column size. Especially in reports with multiple columns it can be quite a task to have all information available on one line. The width and height of a textbox can be defined at design time by setting the Width and Height properties. Since both properties are not available in run-time, you cannot use a complex expression to make a text box fit the widest or longest value. The width must be defined using a single expression in design-time and will be respected in run-time. This does however not apply to the height of a column. Although the Height property cannot be bound to a complex expression either, you can control the height of a text box using the CanGrow and CanShrink properties. The CanGrow and CanShrink properties indicate whether the size of a text box can increase or decrease vertically according to its content. If both properties are set to False, the text box will not grow. The static size of the text box as defined in Visual Studio Report Designer will be used, regardless of the length of its value. If you set CanGrow to True, the text box will expand vertically if the text box is not wide enough to show the value. To allow the text box to shrink based on its contents, you can change the CanShrink property for the text box. If you set CanGrow to True for one text box in a table row, all other cells on the same row might expand vertically too (even if CanGrow for these text boxes is set to False). Unfortunately, CanGrow and CanShrink behave differently for each rendering extension (http://msdn.microsoft.com/en-us/library/cc627537.aspx).
4-18
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations Check Boxes Boolean fields can be displayed in multiple ways. You can use "True/False," "Yes/No," even work with "1/0" or any other combination. You can either use the proper data value of the field or work with expressions to translate the intrinsic value to a different and multi-language enabled presentation. Visual Studio Report Designer does not include a separate check box control. However there is a way to simulate the check box control in reports. For a field to be displayed as a check box, you can change the font of the text box to Wingdings. In addition, you can set the Value property of the text box to an expression similar to: =IIF(Fields!Customer__Print_Statements_.Value = "1", Chr(0254), "o")
New Lines To include line breaks in an expression, you can use the vbCrLf constant: = Fields!Customer_Name.Value & vbCrLf & Fields!Customer_Address.Value & vbCrLf & Fields!Customer__Post_Code_.Value & space(2) & Fields!Customer_City.Value & vbCrLf & Fields!Customer__Country_Region_Code_.Value
You can use this to format text as a block in a textbox. In the previous expression, the address fields will be formatted as a block inside a textbox. If the line break is the last character in a textbox, it will be ignored. (If you have multiple line breaks, only the last one will be ignored.) Other VB constants such as vbTab are not supported inside a textbox. To insert a number of spaces, you can use the Space() function.
Use Rectangles to Keep Objects Together Rectangles can be used either as graphical elements or as containers of objects. As object containers, they keep objects together on a page and control how objects move and push each other. To keep multiple objects together on a page, put the objects within a rectangle. You can then put a page break before or after the rectangle by using the PageBreakAtStart or PageBreakAtEnd properties for the rectangle.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-19
Report Design in Microsoft Dynamics® NAV 2009 Using Rectangles to Control Item Growth and Displacement or Visibility Items within a rectangle become peers of each other and are governed by the rules of how peer items are positioned on the page as they move or grow. For example: •
Items will push or displace each other within the rectangle.
•
Items will not push or displace items outside the rectangle, because they are not their peers.
•
If necessary, a rectangle will grow to accommodate the items it contains.
You can use this logic to your advantage when dealing with objects that expand. For example: •
If you want to leave a blank space in your report for a table to expand into, group the blank space and the table in the same rectangle. When the table grows, it will push the blank space.
•
If you want to prevent a matrix from pushing items off the right edge of the page, put the matrix within a rectangle with blank space to its right. Now, the matrix is no longer a peer to the other item on the page and will not be able to push it until the matrix can no longer be contained within its rectangle.
If you have multiple controls that need to be hidden together, put them inside a rectangle and define the Visibility for the rectangle. The following code sample shows or hides the rectangle (and all controls inside the rectangle) based on the value of a Boolean variable (HideRectangle) on the request options page: =IIF(First(Fields!HideRectangle.Value = True), True, False)
To see if a control is placed inside a rectangle control, check the control's Parent property. The property cannot be edited directly in the Properties window. To change the Parent property, drag the control to another place. Default value for all controls is the section that they are placed in.
Avoid Blank Pages Sometimes, you will see blank pages when outputting reports to a physical page format such as PDF or print. Generally, this will happen when the size of the report body exceeds the size of the page.
4-20
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations For rendering formats that render physical pages (such as PDF), you can set the page height and page width properties for the report to control the pagination. 1. Select Report, Report Properties in Visual Studio Report Designer. 2. In the Report Properties window, click the Layout tab:
FIGURE 4.9 THE REPORT PROPERTIES WINDOW WITH THE DEFAULT PAGE SIZE AND MARGINS
Here you can define the page height and page width along with the different report margins. To ensure that all the contents fit on a single page, the body width plus the margins need to be less than the defined page width. However, some report items can grow horizontally and can cause the width of the body to exceed the page width. Typical examples are matrix data region controls and images set to automatically Autosize or Fit. One thing that is important to know is that setting the Body size at design time is not generally useful in controlling pagination. The body is simply the container for the collection of objects on the report. The design time size of the body represents the smallest amount of space that will be taken up by the report. However, if any objects grow as they are filled with data, the body will expand to contain them. Mostly, the body will grow taller (tables, lists, and text boxes are a few of the items that will cause vertical growth) but can also grow wider (matrices and autosized images can cause horizontal growth).
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-21
Report Design in Microsoft Dynamics® NAV 2009 When the runtime size of the body (plus the page header and footer size, if they are defined) exceeds the specified page size (minus the margins), a physical page break occurs. It is important to understand that controls on the page that do not look like they contain any information (a wide text box) can cause a blank page to be added to the report (when printed or viewed in Print Layout mode) if the control exceeds the page boundaries. Page breaks can also be specified explicitly before or after instances of report items (rectangles, groups, data regions). The Excel rendering format does not explicitly support pagination. The page size and margins are mapped into the Excel document for printing within Excel. For these reports, you will need to specifically include page breaks to break the report into multiple worksheets.
Use Page Breaks to Improve Performance for Large Reports If you do not specify a page size or page breaks for a report that returns a large amount of data, some report formats will try to render the report as a single page. For example, Excel has no default notion of a fixed page size. As a result, if you have a very large report, Excel will try to render it as a single worksheet. In general, using page breaks improves the performance for the users accessing the report, because they can view the first page while the rest of the report is being rendered.
Insert a Page Break Following a Specific Number of Rows in a Table You can use the Ceiling function to group the rows within a table and insert a page break at the end of each group. The Ceiling function returns the smallest number that is not less than the argument. For example, to add a page break after every 30 rows, you can use the following expression to group the rows: =Ceiling(RowNumber(Nothing)/30)
Add Alternating Bars to a Table It is possible for you to create a report that contains a table or matrix in which every other row is shaded. This bar effect makes it easier to visually track the different rows across a page. To more closely simulate the old “green bar” paper that was used at one time to run large reports on high-volume data center printers, you can make the alternating bars green. To achieve this effect, use the Iif() function to assign the background color conditionally, based on whether the row number is odd or even. For example: =IIF(RowNumber(Nothing) Mod 2,"PaleGreen","White")
4-22
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations Add Report Items to the Page Header For long reports, you may want to include text from the body of the report in the header. For example, a directory listing can list the first and last occurrence of the last name field in the header to indicate the range of names included on the page. To do this, you can include an expression using the First() function in a text box in the page header. To display the first occurrence of the LastName value on the page, the expression then resembles the following: =First(ReportItems!LastName.Value)
Likewise, use an expression with the Last() function to provide the last value of the LastName text box on the page. For example: =Last(ReportItems!LastName.Value)
Pagination One key design issue for long reports is controlling where the page breaks occur. Page breaks are controlled by two factors: •
Page size
•
Page breaks specifically included before or after objects
Page Size To control page size, set the page height and width properties for the report by using the following guidelines: •
For rendering formats that render physical pages (PDF), use the PageHeight and PageWidth properties for the report.
•
Some rendering formats, such as Excel, do not support page size. For these reports, it is necessary to specifically include page breaks to break the report into multiple pages.
If the report itself is wider than the defined page width then the report will break across multiple pages horizontally.
Page Breaks You can apply page breaks at the beginning or end of a rectangle, table, matrix, list, chart, or group. Reporting Services tries to keep all the data within the item or grouped together on the same page. To include page breaks specifically before or after items, use the PageBreakAtEnd and PageBreakAtStart properties for the item.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-23
Report Design in Microsoft Dynamics® NAV 2009 Setup Multiple Columns The Report Designer allows you to easily create multicolumn reports. Just like a newspaper, a multicolumn report can conserve space by displaying the report data in more than one column.
FIGURE 4.10 EXAMPLE OF A MULTICOLUMN REPORT
The trick to creating this kind of multi-column report is to ensure that the report data width does not exceed the column width. To view the report rendered correctly in multiple columns, ensure that you preview the report by clicking the Print Layout button. If you just preview the report, you cannot view the data flowing in columns because the preview mode does not take into consideration the page settings. Currently, Reporting Services supports defining multiple columns only at the report level. You cannot, for example, define a multicolumn layout by region, for example, a table region. To define the number of columns, select Report, Report Properties from the menu. On the Layout tab, you can specify the number of columns, the page size and the margins.
4-24
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations When setting up the column widths, you must ensure that you have enough page space to accommodate the number of columns, by using the following formula: Page width-(left margin + right margin) >= number of columns * column width + (number of columns - 1) * column spacing The Report Designer eliminates the trial-and-error fitting game by showing you the outline of the columns in layout mode. This allows you to easily see whether the report width exceeds the page width.
Summary This chapter illustrated how to use the techniques from the previous chapters to build some more advanced reports. It also explained the different export options in the ReportViewer control and how reports are rendered. The chapter also provided useful tips for building reports.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-25
Report Design in Microsoft Dynamics® NAV 2009
Test Your Knowledge Test your knowledge with the following questions. 1. What happens when a report is exported with a multi-level document map to PDF? ( ) The document map is not exported. ( ) The document map is exported without changes to the Bookmarks pane. ( ) Tthe document map is exported but the hierarchy is lost and all items appear on the same level in the Bookmarks pane. ( ) An error message is displayed since it is not possible to export reports with multi-level document maps. 2. What happens when a report with a chart is exported to Excel? ( ) The chart is converted to an Excel chart. ( ) The chart is converted to an image. ( ) The chart is converted to a table. ( ) An error message is displayed since it is not possible to export reports with charts. 3. Which two C/AL functions for exporting reports are added in Microsoft Dynamics NAV 2009? (Select all that apply) ( ) SAVEASHTML ( ) SAVEASPDF ( ) SAVEASXML ( ) SAVEASEXCEL 4. Which operator is used to filter a recordset to the three highest values? ( ) Max(3) ( ) Max N ( ) Top 3 ( ) Top N 5. Which operator is used to filter a recordset to the three lowest values? ( ) !Top N ( ) -Top N ( ) Bottom N ( ) Top N
4-26
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations
Lab 4.1 - Creating Green Bar Reports In this lab you will fine-tune the report created in Lab 1.2 by adding green bar functionality. Scenario Ellen asks Mort to improve the readability of the Inventory report. Instead of having the item number and item name displayed on an orange background, she wants to have the inventory amounts printed with alternating background colors. She also prefers a lighter pastel background color (LightSteelBlue).
Challenge Yourself! Create a green bar matrix report showing the item inventory by location. The rows need to have alternating backgrounds colors. To select the correct colors, use a function that returns either "LightSteelBlue" or "White" every time a new item number is printed.
Need a Little Help? To build the report, execute the following steps 1. Add a custom function to the report 2. Change the background color for the row header cells 3. Change the background color for the other row cells
Step by Step Add a Custom Function to the Report To add a custom function to the report, use the following procedure: 1. Open report 123456701 in Visual Studio. 2. Select Report, Report Properties 3. On the Code tab, add the following custom variable and function:
Private bOddRow As Boolean Public Function AlternateColor(ByVal OddColor As String, ByVal EvenColor as String, ByVal Toggle As Boolean) As String If Toggle Then bOddRow = Not bOddRow End If If bOddRow Then Return OddColor Else
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-27
Report Design in Microsoft Dynamics® NAV 2009 Return EvenColor End If End Function
4. Click OK to close the Report Properties window.
Change the Background Color for the Row Header Cell 1. Select the first cell on the second table row (the cell containing the Item No. and Description fields). 2. In the Properties window, select the BackgroundColor property. 3. Change the Value of the BackgroundColor property to the following expression: =Code.AlternateColor("White", "LightSteelBlue", True).
Change the Background Color for the Other Row Cells 1. Select the second cell on the second table row (the cell containing the Inventory field). 2. In the Properties window, select the BackgroundColor property. 3. Change the Value of the BackgroundColor property to the following expression: =Code.AlternateColor("White", "LightSteelBlue", False). 4. Exit Visual Studio, import the new RDLC layout in the object, save the object and run it.
4-28
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations The result will look similar to this:
FIGURE 4.11 GREEN BAR REPORT PREVIEW
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-29
Report Design in Microsoft Dynamics® NAV 2009
Lab 4.2 - Creating a Top X Report In this lab you will add Top X functionality to report 123456706, Resource Utilization - Chart. Scenario Prakash is looking for some available resources for one of the projects and wants to check the resource utilization. The current report 1106, Resource -Utilization, does not provide this information right away, since it is sorted by resource number and sorting cannot be changed. Prakash wants to see the existing report content replaced by two charts. The first one needs to show the three most utilized resources; the second chart needs to show the five least utilized resources. Finally, he asks Mort not to delete the current report content. Instead, he proposes to hide the content, and include a button or a label that can be clicked to show or hide the details dynamically. After creating a copy of the original report, Mort starts developing.
Challenge Yourself! Make a copy of report 1106, Resource - Utilization and save it as report 80006, Resource - Utilization Chart. Extend report 80006 so that it shows at the same time a Top 3 chart of the three most used and a Top 5 chart of the least used resources. Add a "Show Details" textbox that allows toggling the visibility of the current report content (the table control). The table needs to be displayed under the charts.
Need a Little Help? The following steps shows how to create the Top X Report. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
4-30
Import report 123456706. Reorganize the body section. Include a "Show Details" Textbox to Show/Hide the Table. Format the Show Details Textbox. Hide the Current Report Content. Add a Top 3 Chart for the Most Utilized Resources. Add Data Elements to the Chart Control. Format the Top 3 Chart. Add a Top 5 Chart for the Least Used Resources. Add Data Elements to the Chart Control. Format the Top 5 Chart. Run the report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations Step by Step Import Report 123456706 To import the object in the demonstration database, use the following procedure: 1. 2. 3. 4. 5. 6. 7. 8. 9.
Open the Microsoft Dynamics NAV 2009 demonstration database. Open the CRONUS International Ltd. demonstration company Select Tools, Object Designer to open the Object Designer. Select File, Import. Browse to the report R123456706.fob. Click OK to start the import. In the dialog box, choose to open the Import Worksheet window. In the Action column, verify that the action is set to Create. Click OK to import the object in the database.
Reorganize the Body Section 1. 2. 3. 4. 5.
Open report 123456706 in Visual Studio Report Designer. Select the body section. Change the height of the body section to 4.72 inch. Select the table1 data region control. Move it to the bottom of the body section.
Add a Show Details Textbox 1. In the Toolbox window, select the Textbox control. 2. Click the body section to insert a textbox control. 3. Move the newly added textbox control to the left of the body section. Place it immediately under the Resource_TABLECAPTION__________ResFilter textbox.
Format the Show Details Textbox 1. Select the newly added textbox. 2. In the Properties window, set the Name property to ShowDetails. 3. In the Properties window, set the BackgroundColor property to LightGrey. 4. In the Properties window, set the Color property to Black. 5. In the Properties window, set the TextAlign property to Center. 6. In the Properties window, set the FontWeight property to Bold.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-31
Report Design in Microsoft Dynamics® NAV 2009 Hide the Current Report Content 1. 2. 3. 4. 5.
Open report 123456706 in Visual Studio Report Designer. In the body section, select the table1 data region control. Right-click the grey shaded border and select Properties. In the Properties window, set the Hidden property to True. In the Properties window, set the ToggleItem property to ShowDetails.
Add a Top 3 Chart for the Most Utilized Resources 1. 2. 3. 4.
In the Toolbox window, select the Chart control. Click the body section to insert the chart control. In the Properties window, change the Left property to 0 inch. In the Properties window, change the Top property to 0.79 inch.
Add Data Elements to the Chart Control 1. Double-click the chart control. 2. In the Website Data Sources window, select the Resource__No__ element. 3. Drag it to the Drop Category Fields Here area. 4. In the Website Data Sources window, select the Resource__Usage__Qty___ element. 5. Drag it to the Drop Data Fields Here area.
Format the Top 3 Chart 1. Right-click the chart control and select Properties. 2. In the Chart Properties window, on the General tab, enter the following text in the Title field: Top 3 - Resource Utilization. 3. In the Palette field, select Excel. 4. In the Chart Type field, select Column. 5. In the Chart Sub-type field, select Stacked. 6. On the Data tab, in the Category groups field, select the chart1_CategoryGroup1. 7. Click the Edit button. 8. On the Filters tab, select =Fields!Resource__Usage__Qty___.Value in the Expression field. 9. In the Operator column, select Top N. 10. In the Value column, enter =3.
4-32
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations 11. On the Sorting tab, in the Expression column, select =Fields!Resource__Usage__Qty___.Value. 12. In the Direction column, select Descending. 13. Click the OK button to close the Grouping and Sorting Properties window. 14. On the X Axis tab, check the Show Labels option. 15. On the X Axis tab, check the Side Margins option. 16. On the Y Axis tab, in the Title field, enter Usage (Qty). 17. On the Legend tab, uncheck the Show Legend option. 18. Click OK to close the Chart Properties window.
Add a Top 5 Chart for the Least Used Resources 1. 2. 3. 4.
In the Toolbox window, select the Chart control. Click the body section to insert the chart control. In the Properties window, change the Left property to 3.15 inch. In the Properties window, change the Top property to 0.79 inch.
Add Data Elements to the Chart Control 1. Double-click the chart control. 2. In the Website Data Sources window, select the Resource__No__ element. 3. Drag it to the Drop Category Fields Here area. 4. In the Website Data Sources window, select the Resource__Usage__Qty___ element. 5. Drag it to the Drop Data Fields Here area.
Format the Top 5 Chart 1. Right-click the chart control and select Properties. 2. In the Chart Properties window, on the General tab, enter the following text in the Title field: Bottom 5 - Resource Utilization. 3. In the Palette field, select Excel. 4. In the Chart Type field, select Column. 5. In the Chart Sub-type field, select Stacked. 6. On the Data tab, in the Category groups field, select the chart2_CategoryGroup1. 7. Click the Edit button. 8. On the Filters tab, select =Fields!Resource__Usage__Qty___.Value in the Expression field. 9. In the Operator column, select Bottom N.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-33
Report Design in Microsoft Dynamics® NAV 2009 10. In the Value column, enter =5. 11. On the Sorting tab, in the Expression column, select =Fields!Resource__Usage__Qty___.Value. 12. In the Direction column, select Ascending. 13. Click the OK button to close the Grouping and Sorting Properties window. 14. On the X Axis tab, check the Show Labels option. 15. On the Y Axis tab, check the Side Margins option. 16. On the Y Axis tab, in the Title field, enter Usage (Qty). 17. On the Legend tab, uncheck the Show Legend option. 18. Click OK to close the Chart Properties window.
Run the Report 1. 2. 3. 4. 5.
Exit Visual Studio. Save and import the RDLC changes. Save and compile the report in the Report Designer. Click Start, Run. In the Open field, enter: DynamicsNAV:////runreport?report=123456706 6. Click OK to run the report.
After you click the Show Details button, the report looks similar to this:
FIGURE 4.12 TOP X REPORT PREVIEW
4-34
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 4: Design Considerations
Quick Interaction: Lessons Learned Take a moment and write down three Key Points you have learned from this chapter 1.
2.
3.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
4-35
Report Design in Microsoft Dynamics® NAV 2009
Solutions Test Your Knowledge 1. What happens when a report is exported with a multi-level document map to PDF? ( ) The document map is not exported. ( ) The document map is exported without changes to the Bookmarks pane. (•) Tthe document map is exported but the hierarchy is lost and all items appear on the same level in the Bookmarks pane. ( ) An error message is displayed since it is not possible to export reports with multi-level document maps. 2. What happens when a report with a chart is exported to Excel? ( ) The chart is converted to an Excel chart. (•) The chart is converted to an image. ( ) The chart is converted to a table. ( ) An error message is displayed since it is not possible to export reports with charts. 3. Which two C/AL functions for exporting reports are added in Microsoft Dynamics NAV 2009? (Select all that apply) ( ) SAVEASHTML (√) SAVEASPDF ( ) SAVEASXML (√) SAVEASEXCEL 4. Which operator is used to filter a recordset to the three highest values? ( ) Max(3) ( ) Max N ( ) Top 3 (•) Top N 5. Which operator is used to filter a recordset to the three lowest values? ( ) !Top N ( ) -Top N (•) Bottom N ( ) Top N
4-36
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports
CHAPTER 5: RUNNING REPORTS Objectives The objectives are: •
Use the features of the ReportViewer control.
•
Examine how to add a report to a page and the Departments section.
•
Examine how to create and run hyperlinks to reports from the command prompt, the Start menu, the Desktop and Microsoft Internet Explorer.
•
Understand how to create a hyperlink to a page in the RoleTailored client
•
Understand how to create a hyperlink to a page in a RoleTailored client report.
•
Explore where to find additional resources and information about reporting.
Introduction In Microsoft Dynamics® NAV 2009, reports can be incorporated into menus, or they can be called from, for example, a command button on a form or page. When designing reports, you will often want to run them before they are integrated into the application. In the previous chapters, reports were run from the Start menu. This chapter will show how to integrate the reports into the RoleTailored client interface and how to create hyperlinks to reports.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-1
Report Design in Microsoft Dynamics® NAV 2009
The ReportViewer Control Microsoft Visual Studio® 2005 and 2008 include report design functionality and ReportViewer controls so that you can add full-featured reports to custom applications. Reports can contain tabular, aggregated, and multidimensional data. ReportViewer controls are provided so that you can process and display the report in your application. There are two versions of the control. The ReportViewer Web server control is used to host reports in ASP.NET projects. The ReportViewer Windows Forms control is used to host reports in Windows® application projects. The ReportViewer control processes .rdlc files. Both controls can be configured to run in local processing mode or remote processing mode. How you configure the processing mode affects everything about the report from design to deployment. •
Local processing mode refers to report processing that is performed by the ReportViewer control in the client application. All report processing is performed as a local process using data that your application provides. To create the reports used in local processing mode, use the Report project template in Visual Studio.
•
Remote processing mode refers to report processing that is performed by a Microsoft SQL Server® 2005 Reporting Services report server. In remote processing mode, the ReportViewer control is used as a viewer to display a predefined report that is already published on a Reporting Services report server. All processing from data retrieval to report rendering is performed on the report server. To use remote processing mode, you must have a licensed copy of SQL Server 2005 Reporting Services.
Microsoft Dynamics NAV 2009 uses the ReportViewer 2008 Windows Forms control in local processing mode.
ReportViewer Toolbar The ReportViewer control includes a toolbar that provides navigation, search, export, and print functionality so that you can work with reports in a deployed application.
FIGURE 5.1 THE REPORTVIEWER TOOLBAR
5-2
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports Document Maps The ReportViewer toolbar includes an icon used to toggle a document map on a report. A document map is a navigation area that is attached to the left side of the report view area. It contains a list of links that users can click to navigate to a specific area of the report. Not all reports have a document map; you must define one in the report definition to use this feature. For more information about document maps and other interactive report features, refer to Chapter 2.
Stopping and Refreshing a Report You can use the Refresh and Stop buttons to trigger or stop report rendering. If you click Refresh for a server report that is processed remotely, the report server reprocesses the report with the most recent data. Note that report execution options that are configured on the report determine whether data is actually refreshed or retrieved from cache. The control does not check server report properties, so you must find out from the report server administrator whether the report is configured to use live data. Refresh behavior differs for local processing mode. Because locally processed reports use data that is provided by your application, it is assumed that application code is handling refresh operations. To use the Refresh button on the toolbar, you must provide code that handles the Refresh event. If you do not handle this event, clicking Refresh has no effect. As Microsoft Dynamics NAV 2009 uses local processing, the Refresh functionality will not be available. The Stop button can be used to stop a report when testing RDLC reports or when an RDLC report has slow performance.
Zooming the Report Page The ReportViewer toolbar provides standard zoom functionality so that you can enlarge or shrink the report.
Searching a Report The ReportViewer toolbar includes a search field so that you can find specific text within a report. Search for content in the report by typing a word or phrase that you want to find. The search is case-insensitive and begins at the page or section that is currently selected. Wildcards and Boolean search operators are not supported. Only visible content is included in a search operation. If the report uses show / hide functionality, hidden content is not exposed through search operations. To search for subsequent occurrences of the same value, click Next.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-3
Report Design in Microsoft Dynamics® NAV 2009 Previewing a Report and Setting Page Sizes The ReportViewer toolbar in the Windows Forms control includes commands for viewing a report in print layout and setting page sizes. When you click Print Layout, the ReportViewer toolbar is updated to show just the commands that you can use during preview. Print Layout is a toggle command. You can switch between preview and report session by clicking this button. When clicking Page Size, you can specify page dimensions that are used only for print output. The page dimensions are initialized with values from the report definition, but you can override the values for printing purposes. You cannot save the values with the report.
Exporting a Report The ReportViewer toolbar provides export formats so that you can save a report as an Excel or PDF application file. The same report can have a different appearance and functionality depending on the rendering format you select. Reports that have links, document maps, and bookmarks might not function properly once the report is saved to a file. Depending on how items are aligned in a report, the report layout in a different file format might include extra pages or white space that you did not expect.
Printing a Report The ReportViewer toolbar provides print support. Print support is implemented differently for each version of the control and the processing mode you use. Printing reports from the Windows Forms control uses the print functionality of the operating system.
Print a Report from the RoleTailored Client After a report is created and designed using Visual Studio, you can add the report to the interface of the RoleTailored client to make it available to the end-users. Reports can be added in several ways: in the Action Pane of a page, in the Role Center menu, in the Activities page of a Role Center or in the Departments section.
Adding Reports to a Page The following procedure explains how to make a report available in the RoleTailored client by adding the report to the promoted actions pane in the Item List page. 1. In the Microsoft Dynamics NAV Classic client, open Object Designer, and then click Page. 2. Select the page to display the report, for example, Page 31, Item List. 3. Click Design to open the page in Page Designer.
5-4
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 4. Select an empty line in the designer. Click View, and then Actions to open Action Designer. 5. Scroll down to the ActionContainer that has Reports as its subtype. 6. Select the line that has Inventory - List as its caption. 7. Press F3 to insert a new empty line (or select Edit, New). 8. On the new line, add an action to the list. 9. In the Caption field enter a name for the action: Inventory Matrix. 10. In the Type field, select Action. 11. Click View, and then Properties to open the Properties window for the new action. 12. In the Value field of the RunObject property, click the drop-down arrow and select report 123456701 in the Object List window. 13. In the Properties window, set the Promoted property to Yes, and set the PromotedCategory property to Report. 14. Compile and save the page. 15. Open the RoleTailored client and then open the Item List page.
FIGURE 5.2 THE NEW REPORT IS ADDED TO A PAGE.
The report is added to the list of promoted actions. Click the action to run the report. The report is also available in the Reports menu that appears right above the actions pane.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-5
Report Design in Microsoft Dynamics® NAV 2009 Demonstration: Adding Reports to a Role Center Menu Ellen wants the Inventory Matrix report to be available for her colleague John. Mort will add it to the menu of John's Role Center. 1. In the Microsoft Dynamics NAV Classic client, open Object Designer. 2. Click the Page button. 3. Select page 9009, Whse. Worker WMS Role Center. 4. Click Design to open the page in Page Designer. 5. Select an empty line in the designer. Click View, and then Actions to open Action Designer. 6. Scroll down to the Action that has Customer Labels as its Caption. 7. Click the Separator button to insert a separator. 8. Move the cursor one line down. 9. Press F3 to insert a new empty line (or select Edit, New). 10. On the new line, in the Caption field, enter a name for the action: Inventory Matrix. 11. In the Type field, select Action. 12. Click View, and then Properties to open the Properties window for the new action. 13. In the Value field of the RunObject property, click the drop-down arrow and select report 123456701 in the Object List window.
5-6
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 14. Compile and save the page. 15. Open the RoleTailored client. 16. In the navigation pane, click the Role Center page.
FIGURE 5.3 THE NEW REPORT IS ADDED TO THE ROLE CENTER MENU.
Now the report is added to the role center menu. Click the action to run the report.
Demonstration: Adding Reports to the Role Center Activities John is not that experienced with computers. He regularly calls Mort to ask where he can find the Inventory Matrix report. To help John, Mort will make the report accessible as a link on the Role Center page. 1. In the Microsoft Dynamics NAV Classic client, open Object Designer. 2. Click the Page button. 3. Select page 9056, Warehouse Worker Activities. 4. Click Design to open the page in Page Designer. 5. Scroll down to the Group that has Internal as its Caption. 6. Select View, Actions. 7. On the first empty line, in the Caption field, enter a name for the action: Print Inventory Matrix. 8. In the Type field, select Action.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-7
Report Design in Microsoft Dynamics® NAV 2009 9. Click View, and then Properties to open the Properties window for the new action. 10. In the Value field of the RunObject property, click the drop-down arrow and select report 123456701 in the Object List window. 11. Compile and save the page. 12. Open the RoleTailored client and then open the Role Center page.
FIGURE 5.4 THE NEW REPORT IS ADDED TO THE ACTIVITIES PAGE.
Now the report is added to the Internal group in the Role Center page. Click the action to run the report.
Adding Reports to a Departments Section In Microsoft Dynamics NAV 2009, navigation through the application is done through the use of the Navigation Pane, which is made of MenuSuite objects. MenuSuite objects contain the main menu content that is displayed in the Navigation Pane (in the Classic client) and in the Departments Page (in the RoleTailored client) and have a layered structure. In the Classic client, application objects, such as forms and reports, are accessed from the Navigation Pane. In the RoleTailored client, application objects, such as pages and reports, are accessed from either the Departments page or the Role Center page. The Departments item in the navigation pane of the RoleTailored client provides links to all the pages of the RoleTailored client. The links and pages under
5-8
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports Departments are generated automatically based on the menu suite of the RoleTailored client user. In this way, the Departments page in the RoleTailored client is similar to the Navigation Pane in the Classic client: •
It gives access to reports and forms or pages.
•
It is built using MenuSuite objects.
Unlike any other application objects, the ID of the MenuSuite is defined by C/SIDE depending on the target client and the MenuSuite level. The ID of a MenuSuite for the RoleTailored client is the ID of the MenuSuite for the Classic client with the same level, plus 1000, as shown in the following table. Level
MenuSuite Object in the Classic Client
MenuSuite Object in the RoleTailored Client
MBS
10 MBS
1010 Dept - MBS
Addon 1
51 Add-on 1
1051 Dept - Add-on 1
Compa ny
90 Company
1090 Dept - Company
To modify the Navigation Pane or the Departments Page, you can design the existing or create new MenuSuite objects in the classic client. When creating a new MenuSuite object, you have to select both the target client and the menu level.
FIGURE 5.5 THE DESIGN LEVEL WINDOW
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-9
Report Design in Microsoft Dynamics® NAV 2009 MenuSuites for the RoleTailored client are created and designed in the same way as MenuSuite objects for the classic client. However, when you create menu groups in the MenuSuite for the RoleTailored client, a new property Department Page is available.
FIGURE 5.6 THE GROUP PROPERTIES WINDOW
The Department Page property indicates whether to separate a menu page (containing the underlying menu groups and items) to be built for the group and whether the group needs to appear in the menu structure in the RoleTailored client. When adding menu items to a MenuSuite for the RoleTailored client, you have to specify the Department Category which the menu item belongs to. There are six categories: Lists, Tasks, Reports and Analysis, Documents, History, Administration. The property is used to automatically generate the navigation structure for the RoleTailored client.
Demonstration: Adding Reports to a Departments Section Prakash wants to print the Job Actual To Budget Chart Report (123456709). Instead of printing it through the use of the Start menu, he asks Mort to integrate the report in the Job menu on the Departments section. Mort will first create a new MenuSuite object. 1. In the Microsoft Dynamics NAV Classic client, open Object Designer. 2. Click the MenuSuite button. 3. Click the New button to open the Design Level window. 4. In the Design For field, select RoleTailored Client. 5. In the listbox, select the Dept - Partner level. 6. In the Navigation Pane Designer, select the Jobs menu. 7. Expand the Reports menu group and select the last report in the group: Jobs per Item. 8. Right-click the menu item and choose Create Item. 9. In the Object Type field, select Report. 10. In the Object ID field, click the drop-down arrow and select report 123456709 in the Object List window. 11. In the Caption field, change the caption to Job Actual to Budget Chart.
5-10
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 12. 13. 14. 15. 16.
In the Department Category field, select Reports and Analysis. Click OK to close the Create Item window. Compile and save the MenuSuite. Open the RoleTailored client and then open the Departments page. Click the Jobs item.
Now the new report is added to the Reports and Analysis category:
FIGURE 5.7 REPORT ADDED TO THE DEPARTMENTS SECTION
Hyperlinks to Reports Hyperlinks allow users to send or save quick links to specific pages in Microsoft Dynamics NAV. For example, you can create a hyperlink to a specific list page, such as Customers. This lesson explains how to create and run hyperlinks to reports.
Create Hyperlinks To create a hyperlink, type the Microsoft Dynamics NAV executable service and then type the syntax for the hyperlink. For example: Microsoft.Dynamics.Nav.Client.exe "DynamicsNAV://MyServer/DynamicsNAV/CRONUS International Ltd./RunPage?Page=22"
This example specifies a server name, service, company, and page ID. If entered correctly it opens the RoleTailored client on page 22, the customer list page.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-11
Report Design in Microsoft Dynamics® NAV 2009 Building a URL When you build a hyperlink URL, it can be structured in the following three ways: •
DynamicsNAV://server/service/company/runpage?page=22&bookm ark=0ABA0700235752C7D1
•
DynamicsNAV://server/service/company/runreport?report=901
•
DynamicsNAV://server/service/company/navigate?node=Home/Item s
You can also specify the following additional parameters in a URL.
5-12
Parameter
Description
Personalization ID
Specifies the unique identification used in personalization to store settings in the User Metadata table. If a personalization ID is not found, the page is launched without personalization. Example: DynamicsNAV://localhost/DynamicsNAV/CRONUS International Ltd./runpage?page=22&personalization= 0000232e-0000-001a-0008-0000836bd2d2
Bookmark
Positions the cursor on a single record in a table. Only automatically generated bookmarks are used. If an incorrect bookmark is entered, you will get an error message. Example: DynamicsNAV://localhost/DynamicsNAV/CRONUS International Ltd./runpage?page=22&bookmark= 120000000089083237343
Mode
Used to open a page in a specific mode. Other modes include: view, edit, create, select, and delete. Example: DynamicsNAV://localhost/DynamicsNAV/CRONUS International Ltd./runpage?page=22&mode=View
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports Syntax for Creating Hyperlinks The following table shows some examples of hyperlinks and provides information about how to specify parameters. Parameters
Description
Syntax
Company Name
Allows you to switch a company (case sensitive).
DynamicsNAV://///RunPage?Page=<pageid> Example: Microsoft.Dynamics.Nav.Client.e xe "DynamicsNAV:////CRONUS International Ltd./RunPage?Page=22"
Navigate
Allows users to send or save quick links to specific pages.
DynamicsNAV://///navigate?nod e=<service> Example: Microsoft.Dynamics.Nav.Client.e xe DynamicsNAV://///navigate?nod e=Home/"User Setup"
RunPage
Allows you to run a specific page for testing purposes.
DynamicsNAV:////runpage?page =<page id> Example: DynamicsNAV:////runpage?page =42
RunReport
Allows you to run a specific report for testing purposes.
DynamicsNAV:////runreport?repo rt= Example: DynamicsNAV:////runreport?repo rt=50000
Server name
Allows you to switch servers.
DynamicsNAV://<ServerName>/ //RunPage?Page=<pageid> Example: Microsoft.Dynamics.Nav.Client.e xe DynamicsNAV://MyServer///Run Page?Page=22
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-13
Report Design in Microsoft Dynamics® NAV 2009 Parameters
Description
Syntax
Server name optional port number
Allows you to specify an optional port number in the range 1-65535. The default port is 7046.
DynamicsNAV://<ServerName> ///RunPage?Page=<pagei d> Example: Microsoft.Dynamics.Nav.Client.e xe DynamicsNAV://MyServer:1234 ///RunPage?Page=22
Service instance
Allows you to specify a Service instance. You can find this value in the CustomSettings.config file.
DynamicsNAV:///<Service>//Ru nPage?Page=<pageid> Example: Microsoft.Dynamics.Nav.Client.e xe DynamicsNAV:///DynamicsNAV //RunPage?Page=22
If you omit a parameter, such as Server or Service, do not remove the accompanying forward slash, because this will change the overall structure of the hyperlink. When you type a company name as a parameter, put the hyperlink in quotation marks if there are blank spaces in the name.
Run Hyperlinks In Microsoft Dynamics NAV you can run hyperlinks in different ways. You can run the report from the Run window, from a Command Prompt, from a shortcut or from a browser window. This is useful if, for example, you need to run a specific report for testing purposes or know the ID of a report that is run often. The following demonstrations illustrate how to run hyperlinks.
Demonstration: Running a Report from the Run Window In the Classic client, users can create shortcuts to specific objects on the Windows Desktop. Mort starts to investigate whether this functionality also exists for the RoleTailored client. The first method was already used to test the reports in the previous chapters and labs. To run a report from the Run window, use the following steps: 1. On your machine, click Start and then Run. 2. In the Run dialog box, enter the following command: dynamicssnav:////runreport?report=.
5-14
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 3. Replace with the report ID that you want to use 111. 4. Click OK to run the report. The request options page, if any, will now be displayed in the RoleTailored client.
FIGURE 5.8 THE ROLETAILORED CLIENT WITH THE REQUEST OPTIONS PAGE
Demonstration: Running a Report from the Command Prompt To run a report from the Windows Desktop, you can create a shortcut to the report. To use a shortcut to run a report, follow these steps: 1. Click Start, Run. 2. In the Run window, enter cmd. 3. In the command prompt window, enter the following command:: "C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe" DynamicsNAV:////runreport?report=111. 4. Press Enter.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-15
Report Design in Microsoft Dynamics® NAV 2009 Demonstration: Running a Report from a Shortcut To run a report from the Windows Desktop, you can create a shortcut to the report. To use a shortcut to run a report, follow these steps: 1. On your Windows Desktop, create a shortcut to the Microsoft.Dynamics.Nav.Client.exe. 2. Right-click the shortcut and select Properties. 3. In the Target field, add the hyperlink URL. The complete target will look like this: "C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe" DynamicsNAV:////runreport?report=111. 4. Click OK to close the Properties window. 5. Double-click the shortcut to run the report.
Demonstration: Running a Report from a Browser Window The following steps show how to run a report from the browser window. 1. Open Microsoft Internet Explorer. 2. In the address bar; enter the following URL: DynamicsNav://localhost/DynamicsNAV/CRONUS International Ltd./runreport?report=111. 3. Press Enter to validate the URL. To run a report from the browser, the Microsoft Dynamics NAV 2009 RoleTailored client must be installed on the computer.
Demonstration: Adding a Report Hyperlink to a Web Page Kevin has asked Tim, the IT manager, to conduct a small feasibility study for building a Customer Portal. One of the primary goals of this portal is to provide all outbound sales documents electronically, so the customer can download the documents. In addition, customers must be able to print specific reports themselves. Tim checks whether it is possible to launch a RoleTailored client report from a Web page. 1. From the Start menu, open Microsoft Visual Studio 2008. 2. Select File, New, Web Site. 3. In the New Web Site window, select the ASP.NET Web Site template. 4. In the top right corner, leave the .NET Framework 3.5 option.
5-16
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 5. In the Location field, enter the following path: C:\Documents and Settings\%USERNAME%\My Documents\Visual Studio 2008\WebSites\HyperlinkTest (where %USERNAME% represents your Windows account). 6. In the Language field, select Visual Basic. 7. Click the OK button to create a new web site. 8. Click the Source button at the bottom of the window. 9. Place the cursor between the and tags. 10. Insert the following piece of code: The Customer Top 10 List
The result will look like this:
FIGURE 5.9 THE WEB SITE PAGE IN SOURCE VIEW
11. Press F5 to run the Web site. 12. If the Debugging Not Enabled dialog box is displayed, select the Run without debugging option and click the OK button. 13. Click the hyperlink.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-17
Report Design in Microsoft Dynamics® NAV 2009 Demonstration: Adding a Report Hyperlink to Favorites Now that Tim knows that links to a RoleTailored client report can be included on a Web page, he decides do to a little more testing. Tim wants to know whether links to reports can be added to the Favorites menu in Internet Explorer, and he begins to run the HyperlinkTest site just created. 1. Right-click the The Customer Top 10 List link. 2. Select Add to Favorites. 3. In the Add a Favorite window, enter the following name for the report: Customer - Top 10 List. 4. Click the New Folder button. 5. In the Create a Folder window, enter the following Folder Name: DynamicsNAV Reports 6. In the Create In dropdown list, select Favorites. 7. Click the Create button to create the folder and to return to the Add a Favorite window. Notice that the Create In field points to the newly created folder.
FIGURE 5.10 ADD A FAVORITE WINDOW
8. Click the Add button to close the Add a Favorite window. 9. In Internet Explorer, select Favorites, DynamicsNAV Reports. 10. Click the Customer Top 10 List link. The RoleTailored client will be launched and the request options page for the report is displayed. Tim is satisfied with the results of his tests. He decides to check one more thing. 1. In Internet Explorer, select Favorites, DynamicsNAV Reports. 2. Right-click the Customer Top 10 List link.
5-18
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 3. Select Properties. 4. In the Customer Top 10 List Properties window, click the Web Document tab.
FIGURE 5.11 CUSTOMER TOP 10 LIST PROPERTIES WINDOW
Tim sees that the URL field contains the editable link to the report.
Hyperlinks in E-mails Hyperlinks allow navigating between documents and offer instant access to the right information. This lesson describes to use hyperlinks in e-mail messages. When creating e-mails from C/AL code in the Classic client, you can use the Form.URL method and include it into the body of an e-mail. Whenever someone clicks the Link, the Classic Client is opened and the corresponding Form is shown. In Microsoft Dynamics NAV 2009, in the RoleTailored client, the Form.URL method is no longer supported. The RoleTailored client does not display forms; it uses Pages and Pages do not have an URL method. To create a link to a page, you have to create the URL as follows: dynamicsnav:////runpage?page=<Page No>&bookmark=.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-19
Report Design in Microsoft Dynamics® NAV 2009 Generating BookmarkURLs To get a BookmarkURL for a specific record, you need to use a RecordRef variable that points towards the specific record and use its RecordId property. The next challenge might be that your code is in a Codeunit and can sometimes be called from a form or a page. To make your code compatible with both environments, you can use the ISSERVICETIER function. If you call ISSERVICETIER from the Classic client, then the function returns FALSE. When called from the RoleTailored client, ISSERVICETIER returns TRUE. You can use the following piece of code to include bookmarks in the body of an e-mail:
FIGURE 5.12 C/AL EDITOR WINDOW
Notice the parameters of the FORMAT() function for the RecordRef variable. The usage of value 10 in this expression is a RoleTailored client feature only that will format RECORDID into a text representation that is compatible with the URL handler of reports and pages.
Hyperlinks in a Report With the integration between Microsoft Dynamics NAV 2009 and SQL Reporting Services it is possible to create reports that provide dynamic data. Microsoft Dynamics NAV 2009 reports can among other things include images, graphics, interactive sorting, and toggle on data columns, and it can link to other data in the system. This lesson illustrates how to set up a report to include a link to the customer card page, so that when it is run in preview mode it can look up any existing customer directly from the report. Including this functionality the report no longer serves as a static, printed list, but becomes a dynamic list that can be used for direct drill-down into system data.
5-20
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports Demonstration: Adding a Link in a Report When printing the Customer Top 10 List report, Michael notices that only the customer number and name are included in the list. To find the other customer information, Michael needs to open the Customer Card. He asks Mort whether it is not possible to include a link to the Customer Card in the report. Before he can include the link in Visual Studio, Mort needs to make a small change to the Classic report: he needs to add a variable and include the variable in a hidden textbox on a section.
Add a Variable and Code to the Report 1. In the Classic client, click Tools, and then select Object Designer. 2. In Object Designer, click Report, and then locate the Customer Top 10 List report by typing object ID 111. 3. Select the Customer - Top 10 List report and click the Design button. 4. In the Report Designer window, select the Customer data item, and then click View, C/AL Globals. 5. In the C/AL Globals window, on the Variables tab, add a new entry. 6. In the Name field, enter CustomerRecRef, and in the DataType field, select RecordRef. Close the C/AL Globals window. 7. In the Report Designer window with the Customer data item still selected, press F9 to open the C/AL Editor window. 8. On the OnPreDataItem() trigger, write the following line of code:
CustomerRecRef.OPEN(18);
9. In the Report Designer window, change focus to the Integer data item. 10. In the C/AL Editor window, on the OnAfterGetRecord() trigger, enter the following line of code at the bottom of the trigger:
CustomerRecRef.SETPOSITION(Customer.GETPOSITION);
11. Close the C/AL Editor window.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-21
Report Design in Microsoft Dynamics® NAV 2009 Adding the Textbox Having created the variable CustomerRecRef, Mort must create a new textbox that will be used to get the value of the current customer represented in the dataset in Visual Studio once the layout is opened there. The textbox is not going to be visible on the report when it is run, but is only used for transformation purposes. The following steps illustrate how to add the textbox to the report. 1. With the Customer - Top 10 List report open in Report Designer, click View, and then select Sections. 2. In the Section Designer window, locate the BarText textbox and resize it to make room for a new small textbox. 3. Click View, and then select Toolbox. 4. From Toolbox, click Textbox and then click the report design to place it next to the BarText textbox. 5. Right-click the new Textbox and select Properties. 6. In the Properties window, on the SourceExpr property, enter the following expression: FORMAT(CustomerRecRef.RECORDID,0,10)
7. Close the Properties window. The usage of value 10 in this expression is a RoleTailored client feature only that will format RECORDID into a text representation that is compatible with the URL handler of reports and pages. 8. In the Properties window, set the Visible property to No. 9. Save and compile the report. Once the variable and the textbox are created using Microsoft Dynamics Report Designer, Mort can open the layout of the report and further modify it in Visual Studio. The following steps will add a link to the customer number on the report that opens the customer card for the selected customer. Notice that the newly created textbox is now part of the dataset in Visual Studio under Data Sources and its value is being referenced in the link you are adding. 1. In the Classic client, with the Customer - Top 10 List report open in Report Designer, click View, and then select Layout. 2. In Visual Studio, in the Body section of the report, locate the textbox Customer__No__. The value of the textbox is =Fields!Customer__No__.Value. 3. Right-click the textbox and select Properties.
5-22
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 4. In the Properties window, go to the Navigation tab. 5. Select the Jump to URL option and enter the following expression in the field: ="dynamicsnav:////runpage?page=21&mode=edit&bookmark="+Fiel ds!FORMAT_CustomerRecRef_RECORDID_0_10_.Value
The result will look like this:
FIGURE 5.13 TEXTBOX PROPERTIES WINDOW
Notice that the mode parameter is used. This will allow the user to edit the customer page. 6. Click OK to close the window. 7. Save the report in Visual Studio and return to the Classic client. 8. Save and compile the report in the Classic client. In the Classic client, Mort saves the Customer - Top 10 List report. A message informs him that the .rdlc file for this report has changed and asks if he wants to load the changes. He clicks Yes to save the changes in the database. 1. Select Tools, and then click Compile to compile the report. 2. On the Windows taskbar, click Start and then click Run.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-23
Report Design in Microsoft Dynamics® NAV 2009 3. In the Run window, enter the following string: dynamicsnav:////runreport?report=111 and click OK. 4. Click Preview to view the report. The report lists the top 10 list of customers.
FIGURE 5.14 CUSTOMER TOP 10 REPORT PREVIEW
If resting on the customer number you will get a link to open the specific customer on a separate customer card making it possible to drill down into the customer's data. Microsoft Dynamics NAV 2009 Service Pack 1 will offer Drill Through functionality, so you can create links to other reports.
Interesting Links This section contains a non-exhaustive list of hyperlinks and resources to useful information regarding Microsoft Dynamics NAV 2009 and reporting.
The Microsoft Dynamics NAV Reporting Blog This blog is written by members of the Microsoft Dynamics NAV Reporting Team and dedicated entirely to client-side reporting in Microsoft Dynamics NAV 2009.
5-24
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports The idea with this blog is to collect and share information and tips and tricks for the new reporting environment for Microsoft Dynamics NAV. Also this blog offers the ability to provide feedback directly to the Microsoft Dynamics Reporting Team. http://blogs.msdn.com/nav-reporting
The Microsoft Dynamics NAV Developer Blog This site is written by engineers in the Microsoft Dynamics NAV team worldwide. The blog contains technical articles about Microsoft Dynamics NAV 2009 in general. http://blogs.msdn.com/nav_developer/default.aspx
The Microsoft Dynamics NAV Sustained Engineering Team Blog The Microsoft Dynamics NAV Sustained Engineering Team Blog is mostly written by members of the Microsoft Dynamics NAV Sustained Engineering team. http://blogs.msdn.com/microsoft_dynamics_nav_sustained_engineering/
The Microsoft Dynamics NAV Team Blog This blog site of the Microsoft Dynamics NAV Product team contains technical articles and resources about Microsoft Dynamics NAV. http://blogs.msdn.com/nav/default.aspx
Microsoft Dynamics Developer Center Microsoft Developer Network (MSDN) Developer Centers and Resource Centers pull together content and resources around specific products and technologies. They connect you to code samples, community sites, technical articles and documentation, upcoming events, and much more. The Microsoft Dynamics Developer Center gives access to all kinds of development resources for each of the five Microsoft Dynamics products: (Microsoft Dynamics® AX, Microsoft Dynamics® CRM, Microsoft Dynamics® GP, Microsoft Dynamics NAV, and Microsoft Dynamics® SL). It offers general information such as product highlights, getting started and learning information. Furthermore it contains links to newsgroups, communities and (team) blogs. http://msdn.microsoft.com/en-us/dynamics/default.aspx
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-25
Report Design in Microsoft Dynamics® NAV 2009 Microsoft SQL Server Development Center The Microsoft SQL Server Development Center contains all kinds of resources and information regarding development in Microsoft SQL Server®. http://msdn.microsoft.com/en-us/sqlserver/default.aspx In the Microsoft SQL Server Reporting Services (SSRS) section of the SQL Server Developer Center, you can find all kinds of resources related to reporting in SSRS. To go directly to the SSRS section, click the following link: http://msdn.microsoft.com/en-us/sqlserver/cc511478.aspx
Microsoft Visual Studio Following is the home page of the Microsoft Visual Studio product family. http://www.microsoft.com/visualstudio/
Microsoft Visual Studio Express Editions This site contains resources for the Microsoft Visual Studio Express Editions. The page includes software downloads, samples and resources as well as information about Frequently Asked Questions (FAQ), system requirements, help resources, installation topics, and forums. http://www.microsoft.com/express/
Creating and Consuming a Codeunit Web Service This walkthrough provides an overview of how to create and consume a simple Web service with Microsoft Dynamics NAV. http://msdn.microsoft.com/en-us/library/dd339004.aspx
Microsoft Dynamics NAV 2009 Launch Portal The Launch Portal references tools, training, and content you can use to kick start your Microsoft Dynamics NAV 2009 readiness. This material supplements the communications and processes that are provided by your local Microsoft country or regional organization. A PartnerSource login is required. https://mbs.microsoft.com/partnersource/marketing/campaigns/prospect/launchm dnav.htm
5-26
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports Microsoft Dynamics NAV 2009 Developer and IT Pro Help The Microsoft Dynamics NAV 2009 Developer and IT Pro Help provides information about developing for, installing, and managing Microsoft Dynamics NAV 2009. http://go.microsoft.com/fwlink/?linkid=126283 Updates to the developer and IT Pro Help, with both new content and improvements to existing content can be downloaded from this page: http://go.microsoft.com/fwlink/?linkid=126282
User Experience Guidelines for Microsoft Dynamics NAV 2009 The Microsoft Dynamics NAV 2009 User Experience Guidelines (or “UX Guide” for short) is a tool to assist Microsoft Dynamics NAV Independent Software Vendors (ISVs) in building more user-friendly applications. By using the Microsoft UX Guide proactively during your development process, you can save time and avoid design violations. http://www.microsoft.com/downloads/details.aspx?FamilyID=8B5AB93F-480B4C14-868A-98F6B9BC3E86&displaylang=en
Microsoft Dynamics NAV Developer Documentation This page contains links to several technical articles related to development in Microsoft Dynamics NAV. http://msdn.microsoft.com/en-us/library/dd355683.aspx
The Microsoft Dynamics NAV Technical Community This site offers a wide variety of tools to help you connect and collaborate with other Microsoft Dynamics NAV users, developers and implementers. https://community.dynamics.com/nav/home.aspx
SQL Server 2008 Report Definition Language Specification This document specifies the structure and semantics of the SQL Server 2008 Report Definition Language (RDL), and XML Schema for presenting reports. http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=2 a20c7af-52e8-4882-bd24-9479b3c7517d
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-27
Report Design in Microsoft Dynamics® NAV 2009 Report Design Tips and Tricks This white paper covers best practices on report design and helps you avoid common mistakes when choosing a report layout and output format. Take advantage of existing product features to achieve the results you want. The paper includes report and code examples that implement functionality that is frequently requested (32 printed pages). http://msdn.microsoft.com/en-us/library/bb395166.aspx
Microsoft Most Valuable Porfessional (MVP) and Other Sites www.mibuso.com (http://www.mibuso.com) (MVP Site) www.waldo.be (http://www.waldo.be) (MVP Site) Dynamics User Group (http://dynamicsuser.net/) (Dynamics NAV Online User Community) http://www.dynamicsblog.at/ (Austrian Dynamics blog) http://blogs.msdn.com/german_nav_developer/ (German NAV Developers blog) http://www.plataan.be (Microsoft CPLS)
5-28
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports
Lab 5.1 - Add a Report to the RoleTailored Client In this lab you will add one of the reports built in previous chapters to the RoleTailored client interface. Scenario Prakash wants his Resource - Utilization (Chart) Report (report 123456706) to be available from the Role Center menu, so he and other project managers can access it from the RoleTailored client. He asks Mort to make it available in the menu on the Role Center page. In addition, he wants it to be accessible from the Resources page in the Departments section (under the Reports and Analysis category).
Challenge Yourself! Add report 123456706, created in Lab 4.2, to the Role Center menu for Prakash and the other project managers. Furthermore, create a new MenuSuite object to make the report available under the Reports and Analysis category in the Resources section of the Departments page.
Need a Little Help? The following steps show how to add the report to the RoleTailored client: 1. Add the Report to the Job Project Manager RC Page. 2. Create a New MenuSuite Object. 3. Change the MenuSuite Object to Add the Report to the Departments Section 4. Create a New Shortcut for the RoleTailored client. 5. Change the New Shortcut for the RoleTailored client. 6. Start the RoleTailored Client with the Project Manager profile (in Configuration Mode).
Step by Step Add the Report to the Job Project Manager RC Page 1. In the Microsoft Dynamics NAV Classic client, open Object Designer. 2. Click the Page button. 3. Select page 9015, Job Project Manager RC. 4. Click Design to open the page in Page Designer. 5. Select an empty line in the designer. Click View, and then Actions to open Action Designer. 6. Scroll down to the Action that has Jobs per Item as its Caption. 7. Click the Separator button to insert a separator.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-29
Report Design in Microsoft Dynamics® NAV 2009 8. Scroll down to the ActionContainer that has HomeItems as its Subtype. 9. Press F3 to insert a new empty line (or select Edit, New). 10. On the new line, in the Caption field, enter a name for the action: Resource - Utilization (Chart). 11. In the Type field, select Action. 12. Click View, and then Properties to open the Properties window for the new action. 13. In the Value field of the RunObject property, click the drop-down arrow and select report 123456706 in the Object List window. 14. Compile and save the page. 15. Open the RoleTailored client and then open the Role Center page.
Create a new MenuSuite Object 1. In the Microsoft Dynamics NAV Classic client, open Object Designer. 2. Click the MenuSuite button. 3. Click the New button to open the Design Level window. 4. In the Design for field, select RoleTailored Client. 5. In the listbox, select the Dept - Partner level. 6. Save the MenuSuite object.
Change the MenuSuite Object to Add the Report to the Departments Section 1. In the Navigation Pane Designer, select the Resource Planning menu. 2. Expand the Reports group. 3. Right-click the last report in the Reports group (Resource - Price List) and select Create Item. 4. In the Create Item window, select Report in the Object Type field. 5. In the Object ID field, click the dropdown arrow and select report 123456706 in the Object List window. 6. In the Caption field, change the caption to Resource - Utilization (Chart). 7. In the Department Category field, select Reports and Analysis. 8. Click OK to close the Create Item window. 9. Compile and save the MenuSuite.
5-30
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports Create a New Shortcut for the RoleTailored Client 1. Right-click the Windows Desktop and select New > Shortcut. 2. In the Create Shortcut window, click the Browse button. 3. In the Browse for Folder window, browse to the following path and application: C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe 4. Click the OK button to close the Browse for Folder window. 5. In the Create Shortcut window, click the Next button. 6. Enter the following name for the shortcut: Project Manager Profile. 7. Click the Finish button.
Change the New Shortcut for the RoleTailored Client 1. Right-click the newly created shortcut. 2. Select Properties. 3. Change the Target field to: "C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe" -configure profile:"Project Manager" 4. Click the Apply button. 5. Click the OK button.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-31
Report Design in Microsoft Dynamics® NAV 2009 Start the RoleTailored Client with the Project Manager Profile (in Configuration Mode) 1. On the Windows Desktop, double-click the Project Manager Profile icon. 2. On the Role Center page, click the Reports menu.
FIGURE 5.15 ROLE CENTER PAGE WINDOW
3. Click the Departments menu. 4. Click the Resource Planning section. Now the Resource - Utilization (Chart) Report is listed under the Reports and Analysis category (as the bottom report in the Reports group).
5-32
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports
Lab 5.2 - Call a Report from a Web Service In this lab, you will build a small codeunit and expose it as a Web service. Although this course is not a Web development course, you will see how to build a small Web application that consumes the Web service. This lab is for educational purposes only and does not focus on defining the right application security. Therefore, it is highly recommended not to implement the lab "as is" in a live production environment. Scenario While she is talking to customers, Susan regularly gets requests from customers who have questions about sales invoices and shipments. Currently, Susan carefully takes all the details and sends the case to the responsible representative, who handles it. At the same time, Rebecca gets several requests to resend lost or missing documents to the customers. To better and faster serve the customers, Susan and Rebecca want to quickly search a document (by number) and print a copy of it, so they can add it to the case or send it to the customers. Mort views this as an excellent opportunity to realize one of his dreams: a selfserving customer portal.
Challenge Yourself! Build a Web service that can check whether a specific posted sales document (invoice, credit memorandum and shipment) exists and that can print the specific document as a PDF. Build a small Web application that consumes this Web service; the user needs to specify a document type and a document number and click a Search button. When a wrong document number is entered, a small error message needs to appear to notify the user.
Need a Little Help? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
Create a New Codeunit. Add Global Variables to the Codeunit. Add the CheckInvoiceNo function to the Codeunit. Add code to the CheckDocNo function. Add the GenerateReport function to the Codeunit. Add code to the GenerateReport function. Expose the Codeunit as a Web Service. Create a New Web site. Add Controls to the Web site. Add the Web Service Reference.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-33
Report Design in Microsoft Dynamics® NAV 2009 11. Add Code to Consume the Web Service. 12. Run the Web Application.
Step by Step Create a New Codeunit 1. In the Microsoft Dynamics NAV Classic client, open Object Designer. 2. Click the Codeunit button. 3. Click the New button 4. Select File, Save As. 5. In the ID field, enter 123456701. 6. In the Name field, enter Get Sales Document WS. 7. Check the Compiled field. 8. Click OK.
Add Global Variables to the Codeunit 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
5-34
Select View, C/AL Globals to open the C/AL Globals window. On the Variables tab, select the first (empty) line. In the Name field, enter FileName. In the DataType field, select Text. In the Length field, enter 250. Select the next line. In the Name field, enter SalesInvHdr. In the DataType field, select Record. In the Subtype field, click the button and select the Sales Invoice Header table from the Object List window. Select the next line. In the Name field, enter SalesCMHdr. In the DataType field, select Record. In the Subtype field, click the button and select the Sales Cr.Memo Header table from the Object List window. Select the next line. In the Name field, enter SalesShptHdr.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 16. In the DataType field, select Record. 17. In the Subtype field, click the button and select the Sales Shipment Header table from the Object List window.
FIGURE 5.16 THE C/AL GLOBALS WINDOW
18. Select File, Save to save and compile the codeunit.
Add the CheckDocNo function to the Codeunit 1. In the C/AL Globals window, click the Functions tab. 2. On the first empty line, enter CheckDocNo. 3. Place the cursor on the line containing the CheckDocNo function and click the Locals button to open the C/AL Locals window. 4. On the Parameters tab, select the first empty line. 5. In the Name field, enter DocType. 6. In the DataType field, select Integer. 7. Select the next line. 8. In the Name field, enter DocNo. 9. In the DataType field, select Code. 10. In the Length field, enter 20. 11. Click the Return Value tab. 12. In the Return Type field, select Integer. 13. Close the C/AL Locals window.
Add the GenerateReport Function to the Codeunit 1. In the C/AL Globals window, click the Functions tab. 2. On the first empty line, enter GenerateReport. 3. Place the cursor on the line containing the GenerateReport function and click the Locals button to open the C/AL Locals window. 4. On the Parameters tab, select the first empty line.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-35
Report Design in Microsoft Dynamics® NAV 2009 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
In the Name field, enter DocType. In the DataType field, select Integer. Select the next line. In the Name field, enter DocNo. In the DataType field, select Code. In the Length field, enter 20. Click the Return Value tab. In the Return Type field, select Text. In the Length field, enter 250. Close the C/AL Locals window. Close the C/AL Globals window to return to the C/AL Editor.
Add Code to the CheckDocNo Function 1. In the C/AL Editor, enter the following code in the CheckDocNo() function trigger:
CASE DocType OF 110: BEGIN IF SalesShptHdr.GET(DocNo) THEN BEGIN EXIT(1) END ELSE EXIT(0); END; 112: BEGIN IF SalesInvHdr.GET(DocNo) THEN BEGIN EXIT(1) END ELSE EXIT(0); END; 114: BEGIN IF SalesCMHdr.GET(DocNo) THEN BEGIN EXIT(1) END ELSE EXIT(0); END; END;
5-36
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 2. Select File, Save to compile the codeunit. The function trigger will look like this:
FIGURE 5.17 THE CHECKDOCNO FUNCTION
Add Code to the GenerateReport Function 1. In the C/AL Editor, enter the following code in the GenerateReport() function trigger. // Determine the PDF File Name FileName := 'C:\'; FileName := FileName + FORMAT(CREATEGUID); FileName := DELCHR(FileName, '=', '{-}'); FileName := FileName + '.pdf'; // Print the Document IF DocType = 110 THEN BEGIN SalesShptHdr.SETRANGE("No.", DocNo); IF SalesShptHdr.FINDFIRST THEN REPORT.SAVEASPDF(208, FileName, SalesShptHdr); END; IF DocType = 112 THEN BEGIN SalesInvHdr.SETRANGE("No.", DocNo); IF SalesInvHdr.FINDFIRST THEN REPORT.SAVEASPDF(206, FileName, SalesInvHdr); END; IF DocType = 114 THEN BEGIN SalesCMHdr.SETRANGE("No.", DocNo); IF SalesCMHdr.FINDFIRST THEN REPORT.SAVEASPDF(207, FileName, SalesCMHdr); END; EXIT(FileName);
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-37
Report Design in Microsoft Dynamics® NAV 2009 2. Select File, Save to compile the codeunit. The function trigger will look like this:
FIGURE 5.18 THE GENERATEREPORT FUNCTION
3. Close the C/AL Editor. 4. Close Object Designer.
Expose the Codeunit as a Web Service 1. In the Navigation Pane, select Administration, IT Administration, General Setup, Web Services. 2. In the Web Services window, select a blank line. 3. In the Object Type field, select Codeunit. 4. In the Object ID field, enter 123456701.
5-38
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 5. In the Service Name field, enter Get_Sls_Doc. 6. Place a checkmark in the Published field. The codeunit will now be exposed as a Web service.
FIGURE 5.19 THE WEB SERVICES WINDOW
Test the Availability of the New Web Service 1. Open Internet Explorer. 2. In the browser bar, enter the following URL: http://localhost:7047/DynamicsNAV/WS/services.
FIGURE 5.20 WINDOWS INTERNET EXPLORER WINDOW
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-39
Report Design in Microsoft Dynamics® NAV 2009 The newly published Web service appears in the list with the Service Name specified in the Web Services window. If the list of Web services does not appear, check whether the service "Microsoft Dynamics NAV Business Web Services" is started.
Create a New Web Site 1. Select Start, All Programs, Microsoft Visual Studio 2008, Microsoft Visual Studio 2008. 2. Select File, New, Web Site. 3. In the New Web Site window, select the ASP.NET Web Site template. 4. In the top right corner, leave the .NET Framework 3.5 option. 5. In the Location field, enter the following path: C:\Documents and Settings\%USERNAME%\My Documents\Visual Studio 2008\WebSites\Lab52 (where %USERNAME% represents your Windows account). 6. In the Language field, select Visual Basic. 7. Click the OK button to create the new web site. The result should look similar to this:
FIGURE 5.21 A NEW BLANK WEB SITE
5-40
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports The ASP Editor window in the middle displays a tab for the default page of the Web site, which is called default.aspx. Notice the Design, Split and View buttons at the bottom of the ASP Editor window. 8. Click the Design button to switch to the design view.
Add Controls to the Web Site 1. In the Toolbox window, select the RadioButtonList control. 2. Drag it inside the element on the default.aspx page. The control remains selected on the design surface. 3. Press the right arrow to place the cursor next to the control. 4. Press Enter. 5. In the Toolbox window, select the Textbox control. 6. Drag it inside the element, under the RadioButtonList. 7. With the Textbox control selected, press the spacebar two times to insert two blank spaces after the control. 8. In the Toolbox window, select the Label control. 9. Drag it inside the element, right next to the Textbox. 10. With the Label control selected, press the right arrow key to place the cursor next to the control. 11. Press Enter.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-41
Report Design in Microsoft Dynamics® NAV 2009 12. In the Toolbox window, select the Button control. 13. Drag it inside the element, under the Textbox control. The result will look like this.
FIGURE 5.22 THE NEW WEB SITE WITH CONTROLS
Design the Controls on the Web Site 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 5-42
Select the Textbox control. In the Properties window, set the (ID) property to txtDocNo. Expand the Font property collection. Set the Name property to Verdana. Set the Size property to Small. Select the Label control. In the Properties window, set the (ID) property to lblErrorMsg. Set the ForeColor property to Red. Set the Text property to Error Message. Set the Visible property to False. Expand the Font property collection. Set the Bold property to True. Set the Name property to Verdana. Set the Size property to Small. Select the Button control. In the Properties window, set the (ID) property to cmdSearch. Set the Text property to Search. Expand the Font property collection. Set the Name property to Verdana.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39.
Set the Size property to Small. Select the RadioButtonList control. In the Properties window, set the (ID) property to rblDocType. Expand the Font property collection. Set the Name property to Verdana. Set the Size property to Small. Clik the > button on the top right corner of the RadioButtonList control. In the RadioButtonList Tasks pane, select Edit Items. In the ListItem Collection Editor window, click the Add button. In the ListItem properties window, set the Text property to Posted Invoice. Change the Value property to 112. Set the Selected property to True. Click the Add button. (The newly added item will appear in the Members list.) In the ListItem properties window, set the Text property to Posted Credit Memo. Change the Value property to 114. Click the Add button. (The newly added item will appear in the Members list.) In the ListItem properties window, set the Text property to Posted Shipment. Change the Value property to 110. Click the OK button to close the ListItem Collection Editor window. Select File, Save to save the file.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-43
Report Design in Microsoft Dynamics® NAV 2009 The result will look similar to this:
FIGURE 5.23 WEB SERVICE WINDOW
Add the Web Service Reference As consuming a Web Service is not in the scope for this training, it is recommended to check the online help of Microsoft Dynamics NAV 2009 or the MSDN Web site at http://msdn.microsoft.com/en-us/library/dd339004.aspx. 1. In the Solution Explorer window, right-click the Lab52 project and select Add Service Reference. 2. In the Add Service Reference window, click the Advanced button. 3. In the Service Reference Settings window, click the Add Web Reference button to open the Add Web Reference window. 4. In the URL field, enter http://localhost:7047/DynamicsNAV/WS/services.
5-44
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 5. Click the Go button. 6. In the left listbox, Discovery Page, click the View Service link for the Get_Sls_Doc service.
FIGURE 5.24 THE WEB SERVICE DESCRIPTION
7. Click the Add Reference button to add a reference to the web service.
Add Code to Consume the Web Service 1. Click the Default.aspx tab. 2. Double-click the Search button in Design view. 3. On the Default.aspx.vb tab, enter the following piece of code in the cmdSearch_Click procedure. Dim service As localhost.Get_Sls_Doc = New localhost.Get_Sls_Doc Dim pdfFileName As String Dim DocCheck As Integer service.UseDefaultCredentials = True service.Url ="http://localhost:7047/DynamicsNAV/WS/CRONUS_International _Ltd/Codeunit/Get_Sls_Doc" DocCheck = service.CheckDocNo(rblDocType.SelectedValue, txtDocNo.Text)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-45
Report Design in Microsoft Dynamics® NAV 2009 If DocCheck = 0 Then lblErrorMsg.Text = rblDocType.SelectedItem.Text & " " & txtDocNo.Text & " was not found." lblErrorMsg.Visible = True txtDocNo.Text ="" Else lblErrorMsg.Visible = False service.UseDefaultCredentials = True service.Url ="http://localhost:7047/DynamicsNAV/WS/CRONUS_International _Ltd/Codeunit/Get_Sls_Doc" Response.ContentType ="application/pdf" pdfFileName = service.GenerateReport(rblDocType.SelectedValue, txtDocNo.Text) Response.TransmitFile(pdfFileName) End If
The result will look like this:
FIGURE 5.25 THE CODE TO CONSUME THE WEB SERVICES
4. Click File, Save All to save the modified files.
Run the Web Application 1. On the Default.aspx page, press F5. 2. If the Debugging Not Enabled dialog box is displayed, select the Run without debugging option and click the OK button.
5-46
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports The result will look like this:
FIGURE 5.26 WEB SERVICE WINDOW
Test the Web Application To test the application, use this scenario: 1. Select the Posted Shipment option.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-47
Report Design in Microsoft Dynamics® NAV 2009 2. In the textbox, enter 103007. 3. Click the Search button.
FIGURE 5.27 WEB SERVICE WINDOW
5-48
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports 1. Select the Posted Invoice option. 2. In the textbox, enter 103007. 3. Click the Search button.
FIGURE 5.28 SALES INVOICE REPORT
Summary This chapter described how to create and run hyperlinks to reports for the RoleTailored client. It also explained how to create and use a Microsoft Dynamics NAV Web service that prints a report.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-49
Report Design in Microsoft Dynamics® NAV 2009
Test Your Knowledge Test your knowledge with the following questions. 1. Which functionalities are available from the ReportViewer Control Toolbar? (Select all that apply) ( ) Find ( ) Save Page Setup ( ) Browse ( ) Sort 2. Which property determines whether a menu or menu group will be included as a page in the Departments page of the RoleTailored Client? ( ) Department Menu ( ) Department Page ( ) Department Level ( ) Department Category 3. Which department categories are available in the Create Item window? ( ) Lists, Tasks, Reports and Analysis, Documents, Departments, Home ( ) Lists, Tasks, Reports and Analysis, Documents, History, Setup ( ) Lists, Tasks, Reports and Analysis, Documents, History, Administration ( ) Lists, Tasks, Reports and Analysis, Documents, Departments, Periodic Activities 4. What is the RoleTailored client's equivalent for the Navigation Pane in the Classic Client? ( ) The Role Center Pages ( ) The Activities Pages ( ) The Action Pane ( ) The Departments Page 5. What is true about MenuSuites for the RoleTailored Client? (Select all that apply) ( ) They are stored as separate MenuSuite objects. ( ) They are stored inside the MenuSuite object for the Classic Client. ( ) They compromise the Departments page. ( ) They compromise the Navigation Pane.
5-50
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 5: Running Reports
Quick Interaction: Lessons Learned Take a moment and write down three Key Points you have learned from this chapter 1.
2.
3.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
5-51
Report Design in Microsoft Dynamics® NAV 2009
Solutions Test Your Knowledge 1. Which functionalities are available from the ReportViewer Control Toolbar? (Select all that apply) (√) Find ( ) Save Page Setup (√) Browse ( ) Sort 2. Which property determines whether a menu or menu group will be included as a page in the Departments page of the RoleTailored Client? ( ) Department Menu (•) Department Page ( ) Department Level ( ) Department Category 3. Which department categories are available in the Create Item window? ( ) Lists, Tasks, Reports and Analysis, Documents, Departments, Home ( ) Lists, Tasks, Reports and Analysis, Documents, History, Setup (•) Lists, Tasks, Reports and Analysis, Documents, History, Administration ( ) Lists, Tasks, Reports and Analysis, Documents, Departments, Periodic Activities 4. What is the RoleTailored client's equivalent for the Navigation Pane in the Classic Client? ( ) The Role Center Pages ( ) The Activities Pages ( ) The Action Pane (•) The Departments Page 5. What is true about MenuSuites for the RoleTailored Client? (Select all that apply) (√) They are stored as separate MenuSuite objects. ( ) They are stored inside the MenuSuite object for the Classic Client. (√) They compromise the Departments page. ( ) They compromise the Navigation Pane.
5-52
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix
CHAPTER 6: APPENDIX Objectives The objectives are: •
Understand the way the Form Transformation Tool works
•
Prepare the form transformation process
•
Transform forms to pages
Introduction In Microsoft Dynamics® NAV 2009, the RoleTailored client is the new, rich client and pages are the new way to view, insert, modify, and delete data in the RoleTailored client. The RoleTailored client provides an intuitive and customizable user interface (UI) that you can modify to support the job functions of different work roles in your organization.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-1
Report Design in Microsoft Dynamics® NAV 2009
Understanding Form Transformation The RoleTailored client cannot run forms. You must transform your existing forms into pages. By transforming your forms into pages, you can reuse the business layout and logic of your forms. To transform your forms into pages you must use the transformation tool. The topics in this section describe form transformation, the principles behind form transformation, the different methods that you can use to accomplish the transformation from forms to pages, and an overview of the tool that you use to perform form transformation. The following illustration shows the process of transforming forms to pages:
FIGURE 6.1 TRANSFORMING FORMS TO PAGES
6-2
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Objectives Form Transformation enables you to: •
Transform forms to pages (basic transformation)
•
Tailor resulting pages for the RoleTailored client (UX transformation)
Form-to-page transformation is a basic transformation process that takes form objects from the Microsoft Dynamics NAV Classic application and creates page objects that you can use in the RoleTailored client. User experience (UX) transformation supplements basic form-to-page transformation by adding additional user interface elements to pages that take advantage of the new user experience in the RoleTailored client.
Basic Transformation Basic transformation is the conversion of a form, including its existing functionality and business logic, to a new page by mapping the form essentials— properties, controls and code—to the corresponding page components. The mapping logic is based on rules that are generically applied to all forms. This mapping logic enables you to automate the transformation process. The transformation tool includes built-in mapping rules. In addition to the built-in mapping rules, the transformation input files to the tool include modifiable rules. In addition to replacing existing elements on a form with the corresponding new elements on a page, mapping logic also extends to and includes rules that do the following: •
Ignore: The transformation tool ignores an existing element on a form without replacing it with a corresponding new element on a page. Typically, this occurs in one of the following cases: o o o
•
The RoleTailored client supports the equivalent behavior in a different way than the Classic client. The logic does not require input from the original form. There is not an equivalent element on a page in the RoleTailored client.
Add a property: The transformation tool adds properties to a page that were not on the original form. For example, PageType is a new page property that is a prerequisite to render a page. CardFormID is another new page property. You must assign a CardFormID to a list form that you will transform to a page. Other properties added to a page through transformation are a part of UX transformation.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-3
Report Design in Microsoft Dynamics® NAV 2009 The following tables list examples of generic rules that the transformation tool applies automatically during a basic transformation. Form control
Mapping rule
Page control
TableBox
Replace
Grid (Repeater)
TabControl
Replace
FastTab
Label
In most cases, the CaptionML value of the label is transformed to the CaptionML of the parent or adjacent control.
Caption of field control is used as label.
MatrixBox
Ignore
MatrixBox control is not available.
Form Property
Mapping rule
Page Property
Width
Ignore
None. Pages and controls have built-in rendering and resizing logic.
Xpos
Ignore
None. Pages and controls have built-in rendering and resizing logic.
ParentContr ol
Ignore
None. Pages and controls have built-in rendering and resizing logic.
ID
Replace
ID
Editable
Replace
Editable
RunObject
Replace
RunObject
Tooltip
Ignore
Not supported
NextContro l
Ignore
Not supported
Add new
PageType
Add new
CardFormID
For complete mapping information, see http://msdn.microsoft.com/enus/library/dd301238.aspx.
UX Transformation Through the UX transformation, the automatically generated pages can be tailored to make use of new user interface features in the RoleTailored client. You can either tailor pages through the transformation process or directly in the page object.
6-4
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix You can enhance a page as part of a UX transformation in the following ways: •
Adding FactBoxes and reports to pages.
•
Adding new actions that do not exist on the form.
•
Promoting frequently used actions and reports onto the Action Pane.
•
Assigning icons to actions.
•
Promoting fields to Fast Tab headers.
•
Adding home parts to a role center.
•
Modifying shortcut keys.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-5
Report Design in Microsoft Dynamics® NAV 2009 The following figure illustrates how a form looks before transformation and how the corresponding page looks after transformation.
FIGURE 6.2 SALES ORDER BEFORE AND AFTER TRANSFORMATION
The following changes were made to the sales order task page during UX transformation:
6-6
•
Three FactBoxes were added to the right side of the page: Customer Sales History, Sales Line Details, and Notes.
•
Frequently used actions, such as Post, Post and Print, and Release have been added to the Action Pane with the appropriate icons.
•
The Lines FastTab has been placed directly under the General FastTab.
•
Selected fields, such as Customer Bill-to No., Payment Terms Code, and Due Date have been marked with Essential importance so that they appear as a summary on the collapsed Invoicing FastTab.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Unlike basic transformation, UX transformation requires specific instructions for each form. You define these instructions in the transformation input files. For more information about transformation input files, see Understanding Form Transformation Input Files (http://msdn.microsoft.com/enus/library/dd355283.aspx).
Principles The form transformation tool was designed with the following principles: •
The tool converts all existing Microsoft Dynamics NAV forms into pages while retaining the same functionality as the original forms.
•
Basic conversion rules (built into the tool) assume that the user interface and code on the form are compliant with the standard application development guidelines.
•
The tool identifies deviations from the guidelines that may result in missing user interface (UI) elements or functionality of the original form. The tool logs these deviations for manual consideration.
•
If the rules for modifying the page UI are generic to all pages, then the tool incorporates them into the tool mapping logic. The tool regards rules that represent "manual" decisions about certain user experience (UX) behavior, layout, and business logic as additional input. You define this additional input manually.
These principles turn the transformation into a highly automated process that makes the migration path to the new architecture as efficient as possible. Fully automatic transformation is not possible for the standard global application or for add-ons and customized solutions. This may be caused by the following: •
Some control types in the Classic client are not available in the same form in the RoleTailored client. For example, the MatrixBox and Shape controls are not supported. To generate a page with the same functionality in the RoleTailored client, you have to either replace the original form with an alternate form containing controls that can be transformed, or modify the original form. One of the steps to prepare for form transformation is to redesign forms by either replacing or modifying forms.
•
The RoleTailored client has enhanced behavior hard-coded into its controls. Therefore, some code that was necessary in previous versions of Microsoft Dynamics NAV is now obsolete when using the new controls. This means that pages contain fewer triggers than forms.
•
Automation that has no UI and does some kind of processing which includes generating files as output (or consumes files as part of input) requires special consideration. To make this work, you must rewrite C/AL code to properly supply the input or output files needed for the automation.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-7
Report Design in Microsoft Dynamics® NAV 2009 •
Automation that uses dialog boxes to display messages or errors requires special consideration. The automation may have its own window (like an OCX) or it may interact with hardware that is local on the client (like a bar code reader or card scanner). These are now unsupported scenarios. Any solution to this problem may require a redesign that functions the same way but takes advantage of Web services, C/FRONT.NET, or another integration technology.
The more your forms deviate from the design guidelines of the standard application, the more challenging it will be to transform them successfully to pages so that they support the same functionality and are compliant with UX guidelines. If your goal is to retain one code base in the Classic client and the RoleTailored client, rather than moving all your application development onto the RoleTailored client, you will have to plan for some redesign efforts.
Methods When you decide to migrate an application to the new three-tiered architecture, you must also decide which migration method is best suited to your business needs. Migrating to the new architecture can be an iterative process. You may need to run the form transformation tool multiple times and carefully alter any problematic forms to ensure that pages can be created that have the required layout. It is important to remember that when you transform a form, the form does not change. For each form that you transform, a new page object is created with matching functionality that can be used by the RoleTailored client. You then have two objects—a form and a page. If you run the tool again and transform the same form, the new page that is created will overwrite the first page object. If, at a later date, you decide that you want to change the functionality of your application, you can implement the changes in one of the following ways: •
Implement changes on the form and then transform the form to a page.
•
Implement changes on the corresponding page.
•
Implement changes on both objects, depending on your business needs.
You can choose between the following methods when you move your application from the Classic client to the RoleTailored client:
6-8
•
Reactive Method
•
Proactive Method
•
Start from Scratch Method
•
Combined Method (all of the above)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix The method that you choose can vary from one implementation to another. A good development practice is to use a copy of the database to see which method or combination of methods achieves the best results for each implementation.
Reactive Method The following are the steps for the reactive method: •
Run the Transformation Tool. For more information, see How to: Run the Form Transformation Tool (http://msdn.microsoft.com/enus/library/dd338649.aspx).
•
Check the resulting pages and the log file. For more information, see Reviewing the Form Transformation Log Output File (http://msdn.microsoft.com/en-us/library/dd338760.aspx).
•
Redesign or modify any forms that did not transform successfully. For more information, see Preparing for Form Transformation by Redesigning Forms (http://msdn.microsoft.com/enus/library/dd338598.aspx).
•
Run the tool again to transform the forms that you have altered.
Proactive Method The following are the steps for the proactive method: 1. 2. 3. 4.
Redesign any forms that you know will not transform satisfactorily. Run the Transformation Tool. Check the resulting pages and the log file. Modify forms that are still causing problems.
Start from Scratch Method The following are the steps for the start from scratch method: •
Implement your entire application in the Page Designer and ignore the transformation tool.
Combined Method The following are the steps for the combined method: 1. Transform some forms to pages. 2. If desired, modify the resulting pages in Page Designer to get greater benefit from the new user experience (UX). 3. If desired, create some new pages without transforming the source forms.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-9
Report Design in Microsoft Dynamics® NAV 2009 Overview The Transformation Tool converts form objects in the Classic client to page objects that you can use in the RoleTailored client. The tool uses a set of rules that map objects in the Classic client to objects in the RoleTailored client. These rules are contained both in the transformation input files and in the transformation tool source files. In addition to the transformation input files, which specify the modifiable rules for transformation, the transformation tool uses schema files, a configuration file, and a coderules file to transform the source forms in the forms.xml file into pages. The transformation tool creates a pages.xml file, which contains the pages that you can view in the RoleTailored client, and a log output file. The following illustration shows the form transformation framework and how the transformation tool fits into that framework.
FIGURE 6.3 THE FORM TRANSFORMATION FRAMEWORK
As this illustration shows, transforming forms is an iterative process. You may need to run the transformation tool more than once on a given form to create a page with the functionality that you want. After you run the tool and view the transformed page, you may want to modify some of the rules that the tool uses and produce different page functionality or modify the user interface (UI) for the page. You change the rules by modifying the transformation input files. You can modify these files directly or you can use the Transformation Input Files (TIF) Editor to modify input files.
6-10
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Rules The set of rules that the transformation tool uses can be divided into three categories: •
Generic, built-in rules that are applicable to all forms.
•
Generic, modifiable rules that are applicable to all forms.
•
Non-generic, modifiable rules that are applicable to individual forms.
Built-in rules are part of the transformation tool itself. Modifiable rules are input to the tool in the transformation input files.
Generic, Built-In Rules Most transformation tool rules are used for basic form to page transformations, and are related to controls and properties. These rules ensure that the generated pages contain the same functionality as the original forms. Additionally, there are some rules that specify user interface (UI) behavior that is universal across all pages. For example, a table is always placed second in the control hierarchy of a page, which means that the Lines FastTab appears after the General FastTab and before other FastTabs. All rules in this category are built into the logic of the transformation tool. You cannot change these rules without modifying the source files.
Generic, Modifiable Rules Some transformation rules are specified manually. These rules can be modified and are applied by the tool to all form objects. Examples of generic, manuallyspecified rules are the following: •
Mapping triggers and methods
•
Mapping existing shortcuts
•
Adding new shortcuts
•
Promoting selected commands based on caption (rather than control ID)
•
Assigning icons to commands
These rules are contained in input files to the tool, and are applied when you run the tool. To modify these rules, you either use the TIF Editor or modify the transformation input .xml files directly. For more information about modifying the transformation input files, see the following topics: •
Understanding Form Transformation Input Files (http://msdn.microsoft.com/en-us/library/dd355283.aspx)
•
Specifying Form Transformation Rules with the Transformation Input Files Editor (http://msdn.microsoft.com/enus/library/dd338983.aspx)
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-11
Report Design in Microsoft Dynamics® NAV 2009 Non-generic, Modifiable Rules Some rules are applicable to individual forms, not to the set of all forms. Two of these non-generic rules are required. All other rules in this category are optional and can be applied to pages that you want to modify. The required rules are the following: •
Assigning appropriate PageType properties to all pages.
•
Assigning appropriate CardFormID properties to list pages.
Examples of optional, non-generic rules are the following: •
Ignoring specific pages
•
Ignoring specific controls
•
Replacing one form with another (applicable if a redesigned form is a new form).
All rules in this category are specified manually and therefore, can be modified. Similar to the generic, modifiable rules, these rules are contained in input files to the tool, and are applied when you run the tool. To modify these rules, you either use the TIF Editor or modify the transformation input .xml files directly.
Input The transformation tool uses the following input: •
Forms.xml - All forms that you want to transform, exported as XML files from the Classic client.
•
CodeRules.txt – A set of rules that, through code pattern recognition, maps triggers and methods.
•
Transformation input files. The transformation input files are the following: o o o o o
6-12
TransformPages.xml MoveElements.xml MovePages.xml IgnorePages.xml DeleteElements.xml
•
Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config – An editable configuration file that provides the location of input and output files and defines the scope of logging.
•
XML schema files
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Output The transformation tool produces the following output: •
Pages.xml - Pages that can be displayed in the RoleTailored client.
•
Transformation.log – A file that logs progress information while the tool runs and provides information about issues detected by the tool. After you run the tool, inspect the log file to determine if you need to make changes to the input and run the transformation again. Use the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file to configure the output in the log file.
For more information about how to import and compile the pages in pages.xml, and how to view the new pages in the RoleTailored client, see How to: Import, Compile, and Run Transformed Pages (http://msdn.microsoft.com/enus/library/dd301270.aspx). For more information about the types of information in the log file and how to use the log file, see Reviewing the Form Transformation Log Output File (http://msdn.microsoft.com/en-us/library/dd338760.aspx).
Preparing Form Transformation The transformation process has two stages: •
Preparing for transformation
•
Transforming forms
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-13
Report Design in Microsoft Dynamics® NAV 2009 The following diagram illustrates the process of transforming forms to pages.
FIGURE 6.4 PREPARING FORM TRANSFORMATION
The topics in this section provide an overview of the steps that you need to take to prepare for transformation. If you take the time to prepare your forms for transformation, the transformation will be more efficient and complete. To prepare for transformation, you need to perform the following steps: 1. Install the form transformation tool. For more information, see How to: Install the Form Transformation Tool (http://msdn.microsoft.com/en-us/library/dd339024.aspx). 2. Redesign existing forms in the Classic client. It is not possible to transform some forms, such as Matrix forms. Redesigning forms smoothes the transformation process and helps to minimize errors when you run the tool and layout issues in the transformed page.
6-14
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix 3. Define the transformation input. Create mapping specifications by using the Transformation Input Files (TIF) Editor or by directly modifying the transformation input .xml files. You must assign each page a type. You can also specify additional layout and user experience (UX) changes.
Install the Form Transformation Tool You must copy the form transformation tool files before you can transform forms. The files that you must copy are located in the TransformationTool folder and the TransformationTool\TIF Editor folder on the installation DVD. The TransformationTool folder contains several files, including the .xml transformation input files. For more information about the transformation input files, see Understanding Form Transformation Input Files. The TIF Editor folder contains the TIF.fob and FormToPagetypeMapping.txt files. Before you begin this procedure, confirm the following: •
You have Microsoft Dynamics NAV 2009 installed with a developer license.
•
All Microsoft Dynamics NAV 2009 requirements are met.
To install the form transformation tool, copy the contents of the TransformationTool folder, which includes the TIF Editor folder, from the installation DVD. You can copy these to any location on the Microsoft Dynamics NAV 2009 server.
Redesigning Forms You may need to redesign some of your forms to make them preserve the business logic and layout when you transform the form to a page. Redesigning means that you have to either create a new form to replace the one that cannot be transformed, or modify the original form. Usually you only need to redesign a few forms in your application.
Why Redesign Your Forms? The following reasons may be why you may need to redesign some of your existing forms: •
Unsupported controls
•
Matrix-like layouts do not transform successfully
•
New user experience (UX) guidelines
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-15
Report Design in Microsoft Dynamics® NAV 2009 Unsupported Controls The RoleTailored client does not support certain control types that are used in the Classic client. The unsupported controls are the following: •
MatrixBox
•
Shape
You cannot map these controls in the Classic client to controls in the RoleTailored client. If a form contains one of these types of controls, then it will not transform. Matrix forms are examples of forms that use these types of controls. You must start at the beginning and design a new form.
Matrix-Like Layout Certain controls, when used together, create a matrix-like layout. Although the individual controls are supported, the matrix-like layout will not transform successfully. You must redesign forms with a matrix-like layout.
New UX Guidelines The RoleTailored client has new navigation principles and UX guidelines. This means that you must modify the behavior of some Classic client forms before they can be transformed, for example: •
In the RoleTailored client, the user must always be able to move from a list place to a card.
•
In the RoleTailored client, Journal forms must connect to their respective batch lists
•
In the RoleTailored client, separate list forms must be created for each document type.
Some forms in the standard application were redesigned to new forms for UX improvements. For more information, see http://msdn.microsoft.com/enus/library/dd338598.aspx.
Preparing Transformation Tool Input The transformation input files are XML files that define mapping rules. For most forms, before you transform forms to pages that you can use with the RoleTailored client, you must define the transformation input. Some simple forms do not require input, but for most forms, we recommend that you use the Transformation Input File (TIF) Editor to specify form transformation input files. You can also modify the transformation input .xml files directly instead of using the TIF Editor. This topic describes the TIF Editor and the workflow that you use to create and modify transformation input files by using the TIF Editor.
6-16
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Elements of the Transformation Input File Editor The user interface for the TIF Editor is a form that you run from Object Designer in the Classic client. The form that you run is form 177000, Transformation Forms. In this way, the TIF Editor offers a familiar environment for creating and modifying the transformation input in a tabular format rather than in the XML file. If you use the Microsoft Dynamics NAV Developers Toolkit, the TIF Editor also has data about form objects, which significantly improves efficiency and accuracy of the input data entry. The TIF Editor consists of the following objects: •
TIF.fob – A set of objects that make up the editor’s functionality.
•
FormToPageTypeMapping.txt - A list of form types, definitions, and their matching page types.
•
Schemas - TransformationInput.xsd, DeletePageElement.xsd, IgnorePage.xsd, IgnorePage.xsd, and MovePageElement.xsd
Transformation Input File Editor Workflow In your application, you may have forms that are the standard application forms, with or without customizations, and you may have Microsoft Certified Partner solution forms. The following steps summarize the workflow for the TIF Editor. Some steps in the workflow are optional, based on whether you have standard application forms or partner solution forms. 1. Install the TIF Editor. 2. If you have standard application forms, import the standard application transformation input files to view and modify transformation input specifications. 3. If you have partner solution forms, populate the TIF Editor with these forms. 4. Import the list of form types, definitions, and their matching page types, to be used for lookup. 5. Specify the page type for partner solution forms. The standard application forms already have the page type specified. 6. Specify the CardFormID for list forms that have associated cards and that are partner solution forms. The standard application forms already have the CardFormID specified. 7. Define additional input specifications for the form transformation. 8. Validate form transformation. 9. Export the input data out of the TIF Editor to create XML input files. The files are validated against the XML schemas.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-17
Report Design in Microsoft Dynamics® NAV 2009 Evaluating Client Files and Automation Before you move to the three-tiered architecture in Microsoft Dynamics NAV 2009, you must evaluate your files that reside on the client to determine whether you need to use different functions to upload or download those files. You must also evaluate your automation components to determine whether you need to use different functions, change code, or redesign them
Files In the Classic client, if the application creates a file, then that file is created on the local client computer. In the RoleTailored client, if the application creates a file, the file is created on Microsoft Dynamics NAV Server. If you need to store a file on the client computer, then you must write code to download the file from Microsoft Dynamics NAV Server to the client. Similarly, if the application must access a file that is stored on the client, then you must write code to upload the file from the client to Microsoft Dynamics NAV Server. The following examples demonstrate scenarios that access files: •
Reports or batch jobs in which the output is saved to a file
•
COM components that generate or consume files
The following table describes guidelines to determine what you must modify to work with files in the RoleTailored client.
6-18
Description of file
Change required
File is used for processing only
No change is required.
File is generated on the server and is provided to the user
Use the DOWNLOAD Function (FILE) or DOWNLOADFROMSTREAM Function (FILE) in C/AL.
File is provided from the client and sent to the server
Use the UPLOAD Function (FILE) or UPLOADINTOSTREAM Function (FILE) in C/AL.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Automation Components The following table describes guidelines to determine if you must modify your automation components for use in the RoleTailored client. Description of automation component
Change required
Component contains no UI and no client interaction and is for processing only
No change is required.
Component contains no UI and makes a file for a client
Use guidelines for files (see preceding table).
Component contains no UI and accesses local software or network resources, such as MSMQ
You may need to change code to make the computer resource path more explicit.
Component accesses client-local resources, for example, a Gantt server, or client-local hardware, for example, electronic scales
Component is not supported for use with the RoleTailored client. You must redesign using Web services.
Transforming Forms The transformation process has two stages: •
Preparing for transformation
•
Transforming forms
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-19
Report Design in Microsoft Dynamics® NAV 2009 The following illustration shows the process of transforming forms to pages.
FIGURE 6.5 FORM TRANSFORMATION
The topics in this section provide an overview of the steps that you need to take to transform forms to pages. The steps to transform forms are the following: 1. 2. 3. 4. 5.
Export your existing forms to an .xml source file. Configure the log file settings and the input and output file locations. Run the tool. Review the log file. If any forms did not transform successfully, you may need to make changes to your existing forms or to the input files and then retransform forms. 6. Import and compile the transformed pages into the Classic client so that you can view and use the pages in the RoleTailored client. 7. (optional) Transform the navigation pane in the Classic client to Departments in the RoleTailored client by transforming the MenuSuite object.
6-20
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Create Forms.xml Source File To transform forms to pages, you must create a source .xml file of the forms that you want to transform. The form transformation tool uses this source file as well as the transformation input .xml files and the schema files to transform forms to pages. This procedure describes how to create the source forms .xml file. Before you begin this procedure, confirm that you have completed the necessary preparation for transforming forms The following list of steps shows how to create the forms.xml input file. In the Classic client, click Tools, and then click Object Designer. 1. 2. 3. 4.
In Object Designer, click Form. Select the forms that you want to transform. Click the File menu, and then click Export. In the Export Objects window, browse to the location where you want to export the forms. We recommend that you export forms to the same folder where the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe file and the transformation input files reside. 5. In the File name text box, specify the name of the file. We recommend that you name the file Forms.xml. 6. In the Save As Type drop-down list, select XML Format (*.xml), and then click Save. NOTE: After you have save the forms to the Forms.xml file, the next step in the transformation process is to configure the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file. When you configure this file, verify that it specifies the correct name and location for the exported forms XML file.
Configuring the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.c onfig File Use the form transformation configuration file, Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config, for the following purposes: •
To define file names and path locations for input and output files. The form transformation tool references these files during execution.
•
To define the scope of logging by specifying what types of exceptions you want to include in the output log file.
If you have saved your files to the default locations and if you want to use the default scope of logging, then you do not need to modify the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-21
Report Design in Microsoft Dynamics® NAV 2009 File Locations By default, the location of the input and output files is the same as the location of the tool. The configuration file contains the following lines, which specify the names and locations for input and output files.
You can change this information in the configuration file if you want to use input files from a different folder or if you change the names of the input or output files.
Scope of Logging You can control the size and focus of your log file by including only the exceptions in which you are most interested. The following table describes the exception message types.
6-22
Message Type
Description
ChangeCodeManu ally
Transformation of a specified control or property could not be completed. Additional, typically manual, change or input is required to address the exception that is associated with this message.
CheckInputFile
There is an inconsistency in an input file.
CodeCannotBeTra nsformed
Code cannot be transformed automatically. Manual change to the form itself is needed.
DeleteTriggers
Specified trigger is not supported in the RoleTailored client and therefore, has been automatically deleted by the tool. Code from trigger will be moved to a new function and a call to this function will be typically be added to some other trigger.
Error
Any error. Typically, the transformation tool cannot recover after such an error.
General Information
Any information. Typically, no action is required.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Message Type
Description
IgnoreForms
Specified form was excluded from the transformation and no matching page was created.
IgnoreWarning
Verify that there is not an issue, and then ignore this warning.
InputInformation
Information about input files.
RemoveControls
Specified control on the form was not mapped to a matching control on a page.
RemoveProperties
Specified property on the form cannot be mapped to a matching property on a page.
TempCodeWash
Message that is triggered by a code transformation.
ValidateManually
Specified control or code has been changed during transformation. The change requires manual validation.
Warning
Any warning. Requires manual validation.
To configure which type of messages to include in the log file and the degree of message details, you assign a value code to each message type in the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file, and then set the TraceLevelSwitch value to specify the logging level. The following example from the configuration file shows the default value code assignments for each message type.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-23
Report Design in Microsoft Dynamics® NAV 2009 Based on the preceding value codes, the default logging levels can be described as follows: •
1 Logs error messages and required information
•
2 Logs errors and warnings
•
3 Logs detailed error information
•
4 Logs verbose information
•
0 Logging is turned off
To specify the level of logging, you set the TraceLevelSwitch value. For example, in the following code, the logging level is set to 1, log error messages and required information.
You can modify the level of logging or the value code for each message type in the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file.
Run the Transformation Tool The following procedure describes how to run the form transformation tool to transform forms for the Classic client to pages that you can use in the RoleTailored client. Before you begin this procedure, you must do the following: •
Complete the necessary preparation for transforming forms.
•
Create the source forms.xml file.
•
Configure the input and output file locations and the level of logging.
The following list of steps shows how to run the form transformation tool. 1. Confirm that you have the following input files, and that the path to these input files is correct in the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file: o Forms.xml o CodeRules.txt o TransformPages.xml o IgnorePages.xml o MovePages.xml o DeleteElements.xml o MoveElements.xml o DeletePageElement.xsd o IgnorePage.xsd o MovePage.xsd o MovePageElement.xsd o TransformationInput.xsd 6-24
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix o o
Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config Microsoft.Dynamics.Nav.Tools.FormTransformation.exe
2. Navigate to the folder where Microsoft.Dynamics.Nav.Tools.FormTransformation.exe is located. 3. Double-click Microsoft.Dynamics.Nav.Tools.FormTransformation.exe. 4. Verify that the tool completes successfully and that you have the following output files in the folder specified in the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file: o Pages.xml o Transformation.log o TransformationLog.xml (contains the same information as Transformation.log) After you run the transformation tool, you must complete the following steps: •
Inspect the log file for errors.
•
If necessary, re-transform all or selected forms.
•
Import and compile pages.
Review the Form Transformation Log Output File After you run the form transformation tool, the pages that the tool created might not contain functionality that is equivalent to the original forms and might not display correctly in the user interface. You can use the information captured in the log file to help you to diagnose problems. By inspecting the log file, you can identify issues before you deploy the new page objects in the RoleTailored client. To resolve these issues, you must modify the input to the form transformation tool and run the tool again. This topic describes the information that is in the transformation log files. The same information is captured in the following log files: •
Transformation.log
•
TransformationLog.xml
For more information and examples of log messages, see Reviewing the Form Transformation Log Output File (http://msdn.microsoft.com/enus/library/dd338760.aspx).
Re-Transform Pages After you run the form transformation tool, you might discover errors or warnings in the transformation log file or issues with the page in the RoleTailored client. Form transformation is an iterative process. If the first transformation does not successfully convert all your forms into pages, then you may need to make changes and run the transformation tool again.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-25
Report Design in Microsoft Dynamics® NAV 2009 Before you begin this procedure, be sure that you have reviewed the Transformation.log file and that you understand any errors or warnings. To re-transform pages, execute the following list of steps: 1. If needed, make changes to the source form objects. . 2. If needed, make changes to the transformation input files. 3. If you have modified any source form objects, re-create the Formsl.xml source file. 4. Re-run the tool until you have transformed all your forms successfully.
Import, Compile and Run Transformed Pages After you have run the form transformation tool, you must import the Pages.xml file into Object Designer. Pages.xml contains all the metadata required to display your transformed forms as pages in the RoleTailored client. You must also compile all of the new page objects so they are compatible with the .NET Framework and the Microsoft Dynamics NAV architecture. After you import and compile the transformed pages, the Microsoft Dynamics NAV database contains both your original Classic client forms and your new page objects. You can run the RoleTailored client and view the transformed pages. Before you begin this procedure, you must successfully run the form transformation tool. 1. In the Classic client, click Tools, and then click Object Designer. 2. Click the File menu, and then select Import. 3. In the Import Objects window, in the Files of type drop-down list, select XML Format (*.xml), browse to the folder where the Pages.xml file is located, select Pages.xml, and then click Open. By default, the Pages.xml file, which was created when you ran the form transformation tool, is located in the same folder as the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe file and the transformation input files. If you changed the name or the location of the output .xml file in the Microsoft.Dynamics.Nav.Tools.FormTransformation.exe.config file, select the name of the file that you specified. 4. In Object Designer, click Page, and then select all the pages that you imported. 5. From the Tools menu, select Compile, and then click Yes. 6. Run the RoleTailored client to view your transformed pages. NOTE: To view a specific page in the RoleTailored client, run the following command from a Command Prompt window. DynamicsNAV:////runpage?Page=<PageID>
6-26
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix Transforming MenuSuite Objects In the Classic client, you access forms and reports from the navigation pane, which displays menus that are contained in a MenuSuite object. In the RoleTailored client, you navigate to pages and reports by using the following elements: •
Role Centers
•
Departments
You can transform a MenuSuite object that you use in the Classic client to a Departments page that you use in the RoleTailored client. The Departments page contains the entire suite of functionality as licensed and available to the company. In this way, the Departments page in the RoleTailored client is similar to the navigation pane in the Classic client. The Departments page is also a MenuSuite object with a layered item structure but is designed specifically for the RoleTailored client. In Microsoft Dynamics NAV 2009, when you create a new MenuSuite object, you must select either the Classic client or the RoleTailored client as the target. If you support both the Classic client and the RoleTailored client, you must maintain two sets of MenuSuite objects. The ID of a MenuSuite object for the RoleTailored client will be the Classic client ID plus 1000, as demonstrated in the following table. MenuSuite object in the Classic client
MenuSuite object in the RoleTailored client
10 MBS
1010 Dept - MBS
51 Add-on 1
1051 Dept - Add-on 1
You transform a MenuSuite object by using the Transformation Input File (TIF) Editor. The MenuSuite transformation creates a suggestion for a Departments page that is based on the navigation pane, transformation rules, and input. After you transform the MenuSuite object, you must verify whether you need to make additional updates to the transformed Departments page. The RoleTailored client has different functionality and different user experience (UX) requirements than the navigation pane in the Classic client. The additional updates that you make to the transformed Departments page can take advantage of the new functionality.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-27
Report Design in Microsoft Dynamics® NAV 2009 To reduce the number of these manual updates that you have to make after transformation, verify that you meet the following conditions before transforming a MenuSuite object. Condition
Reason
PageType is assigned to all form objects.
Form objects will be placed in a Department Category based on PageType.
CardFormID is assigned to all list form objects with a card.
Card Form IDs in MenuSuite will be replaced with the related list.
Microsoft Dynamics NAV Developer Toolkit is installed to provide data about which reports are ProcessingOnly reports.
ProcessingOnly reports are placed in the Tasks category on department pages. Other reports are placed in the Reports and Analysis category on department pages.
An example of a MenuSuite transformation can be found on How to: Transform a MenuSuite Object (http://msdn.microsoft.com/en-us/library/dd354979.aspx).
Summary More information is available on Transforming Forms to Pages (http://msdn.microsoft.com/en-us/library/dd338789.aspx).
6-28
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
Chapter 6: Appendix
Quick Interaction: Lessons Learned Take a moment and write down three Key Points you have learned from this chapter 1.
2.
3.
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
6-29
Report Design in Microsoft Dynamics® NAV 2009
6-30
Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement