Top Banner
Chapter 2: Master Tables and Pages 2-1 CHAPTER 2: MASTER TABLES AND PAGES Objectives The objectives are: Use formalized analysis and design methodology. Understand master table and page standards. Work with table event triggers. Work with the complex data types and their member functions. Enable multi-language functionality. Define the strategy for implementing Customers and Participants, Create the tables to manage the seminar rooms. Create instructor data management. Create seminar data management. Test the master tables and pages by following a test script. Introduction In this chapter the requirements for master tables and pages for the solution are discussed before moving on to the Design and Implementation phases. The planning documentation in chapter 1 is used as a reference, particularly for the Analysis phase. Review the functional requirements in chapter 1 for general use case requirements. For example, the functional requirements state, "Customers can register one or more participants for a seminar." Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
38

Na2009 enus devii_02

Nov 07, 2014

Download

Technology

Peter Muscat

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-1

CHAPTER 2: MASTER TABLES AND PAGES Objectives

The objectives are:

• Use formalized analysis and design methodology. • Understand master table and page standards. • Work with table event triggers. • Work with the complex data types and their member functions. • Enable multi-language functionality. • Define the strategy for implementing Customers and Participants, • Create the tables to manage the seminar rooms. • Create instructor data management. • Create seminar data management. • Test the master tables and pages by following a test script.

Introduction In this chapter the requirements for master tables and pages for the solution are discussed before moving on to the Design and Implementation phases. The planning documentation in chapter 1 is used as a reference, particularly for the Analysis phase. Review the functional requirements in chapter 1 for general use case requirements. For example, the functional requirements state, "Customers can register one or more participants for a seminar."

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 2: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-2

A Quick Refresher In this chapter master tables, pages and triggers are all used to support the data required to implement the Serminar Management solution. Also, this chapter will enable multi-language support in some of the labs. These are concepts already familiar to those who have used Microsoft Dynamics NAV and completed the C/SIDE Introduction in Microsoft Dynamics® NAV 2009 course. These tools and concepts are reviewed here as a quick refresher.

Tables

Tables define the structure for and storage of the data upon which a solution relies. Tables are stored in a database, either the Microsoft Dynamics® NAV database or SQL server, depending on the installation. At this point, the application code is not affected by the database choice. Performance implications depending on the database being used are discussed later.

Master tables define the data-foundation upon which a solution relies. A solution may use additional non-master tables. Non-master tables contain information that is derived from the master tables.

In this chapter master tables are created to support the data required to implement the solution.

Pages

Master pages are pages that support the display and modification of the data stored in the master tables. There are two types of master pages in Microsoft Dynamics NAV as follows:

• Card pages • List pages

Both types are explicitly tied to master tables. The primary difference is that card pages display one record at a time, and list pages display multiple records at one time. In the RoleTailored client, clicking on an action for a master table will take you first to the associated list page from which you can access the cad page for a specific record.

Triggers

Triggers are methods that execute when a system event occurs or when they are invoked by calling code. There are two types of active triggers, triggers that contain executable code.

Event Triggers, which have names that start with "On..." fire when specific events occur. Example events are the insertion, modification or deletion of data.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 3: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-3

Function Triggers are Developer defined (either as part of the base system or added as part of a customization). These triggers execute when they are called by coded logic.

There is a third type of trigger, Documentation Triggers. Documentation Triggers contain no executable code, but contain only free-form documentation. These are intended to allow developers to document at the object level changes that they have made.

This chapter explains how Event Triggers can be used to validate data values entered by the user.

Multi-Language Support

Microsoft Dynamics NAV is multi-language enabled. This means that a localized version of Microsoft Dynamics NAV can present itself in different languages. In other words, two or more clients tied to the same database can present their User Interface in two or more different languages at the same time. Users can change the choice of language that is used to display text, and the change is immediate. There is no need to stop and restart Microsoft Dynamics NAV.

Before starting to work in a multi-language-enabled database, set the working language to English - United States. Click Tools, click Language, and then select English - United States.

To enable multi-language functionality when developing solutions, there are a few guidelines to follow.

• When creating objects in Microsoft Dynamics NAV, the Name property of an object must always be in English - United States (ENU), and it must never be visible to the user.

• Language-specific names must be provided in the CaptionML property.

In this chapter, multi-language support is enabled in some of the labs.

Customers and Participants These two entities are key parts of a solution that provides a way to schedule seminars that are attended by participants and paid for by customers. This section discusses the strategy for implementing customers and participants.

Solution Analysis

Even at this early stage, it is clear that representing customers and seminar participants requires master tables and pages, but it is important to resist the temptation to create these items immediately.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 4: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-4

Regarding customers and seminar participants, the functional requirements in Chapter 1 stated:

"Seminar participants come from a company that is set up as a customer in Microsoft Dynamics NAV. Every customer can register several participants for a seminar, but participants cannot be registered unless they are connected with a customer. This is necessary to invoice customers for the participation of their related contacts at seminars."

This means that there must be a one-to-many relationship between customers and seminar participants. This is an important fact to consider during the design phase.

The functional requirements also mention the need to invoice customers. This implies that a table with only a company name does not suffice. For example, the table used to represent customers must be complete with addresses, phone numbers, and accounts numbers. The exact requirements call for an analysis of all the solution elements, especially reports. However, this level of detailed analysis is not necessary in this course scenario.

Solution Design

Before moving into the Implementation phase and creating new tables and pages, determine if any existing elements can be used instead. This helps to save time developing and debugging.

Microsoft Dynamics NAV has many built-in tables and pages, and there are some that work for representing customers and seminar participants. These tables and forms are as follows:

Table Page

18 Customer 21 Customer Card

22 Customer List

5050 Contact 5050 Contact Card

5052 Contact List

The Customer tables and pages can be used to represent customers that enroll seminar participants. Participants can be represented by the Contact tables and pages.

Additionally, there is a one-to-many relationship between the Customer and Contact tables in Microsoft Dynamics NAV, so this meets the requirements for this solution.

Development

In this case, because of the complete Analysis and Design phases, no new development is necessary.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 5: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-5

Rooms The next step is to create the tables to manage the seminar rooms in which the seminars are held.

Solution Analysis

The client's functional requirements describe the management of seminar rooms in this way:

Each seminar is held in a seminar room. Some are held in-house and some are held off-site. If a seminar takes place in-house, a room must be assigned. For off-site rooms, the rental rate must be tracked as well.

This description makes it clear that the table and pages used to represent seminar rooms need – at minimum – the location and number of the room, whether it is on-site or off-site, and the rental rate.

Solution Design

The analysis of the room management process shows the need for only one basic table, a Seminar Room table, and the associated Card and List pages.

The tracking of prices and costs is the complex part of representing rooms. However, the Resource table (156) provides a way of tracking this kind of information for company resources, such as employees or machinery. Leveraging the Resource table and its built-in behaviors eliminates the need to duplicate this functionality in the new Seminar Room table. The new table is associated with both the Contact table and the Resource table, as shown in the image.

FIGURE 2.1 RELATIONSHIP BETWEEN SEMINAR ROOMS, RESOURCES, AND CONTACTS

Before proceeding, review the pages as they appear when implementation is complete.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 6: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-6

The Seminar Room Card page, as shown in the image, displays one room at a time, and can be used to modify the data in the Seminar Room table.

FIGURE 2.2 SEMINAR ROOM CARD PAGE (123456703)

The Seminar Room Card page has two FastTabs:

• A standard General FastTab • A Communication FastTab

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 7: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-7

The Seminar Room List page (123456704) allows multiple rooms to be displayed at once. It provides an overview of the seminar rooms, but does not allow the underlying Seminar Room table to be modified.

FIGURE 2.3 SEMINAR ROOM LIST (PAGE 123456704)

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 8: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-8

Lab 2.1 - Create Seminar Room Tables and Pages Part of developing any solution is to tag and document objects when working on them, and thereby leaving a trail of all the changes that are made to the object. A short tag will go into the Version List Field in the object designer, which identifies the modified project. One example of such a tag is "CSD.02.01", which is short for C/SIDE Solution Development, Chapter 02, Lab 01. For simplicity, use the tag "CSD" in the version list.

Inside each object that is modified include a short description of the change in the documentation trigger. It is recommended that this short description include the project tag, the date, the developer's name, and a short description of the change itself.

FIGURE 2.4 THE DOCUMENTATION TRIGGER

Scenario

To begin the development of the Seminar module, the Seminar Room table must be created so that it can be integrated later with the base Microsoft Dynamics NAV 2009 system. Appropriate card and list pages to allow data entry and inquiry must also be developed and tested.

Step by Step

1. In the Comment Line table (97), add the option Seminar Room to the options for the field Table Name. It is recommended to add a few commas (unused options) before entering the new option value. This prevents an upgrade issue if Microsoft later adds new options to this field in the core application. Ensure that this change is also reflected in the same manner in the OptionCaption and the OptionCaptionML properties. The number of empty options (for example, commas) to add is an arbitrary decision, so in these labs, add five extra commas.

2. In the Extended Text Header table (279) and the Extended Text Line table (280), add the option Seminar Room to the options for the field Table Name. As with the Comment Line table, add five commas before the new option value, to keep some room for future additions to the option string. Ensure that the change is reflected in the caption properties as well.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 9: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-9

3. Create the Seminar Room table (123456702) with the following fields:

No. Field Name Type Length Comment

1 Code Code 10 Must not be blank

2 Name Text 50

3 Address Text 50

4 Address 2 Text 50

5 City Text 30

6 Post Code Code 20 Relation to the Post Code table (225)

7 Country/Region Code

Code 10 Relation to table 9 Country/Region

8 Phone No. Text 30 ExtendedDataType = Phone No.

9 Fax No. Text 30 ExtendedDataType = Phone No.

10 Name 2 Text 50

11 Contact Text 50

12 E-Mail Text 80 ExtendedDataType = E-Mail

13 Home Page Text 90 ExtendedDataType = URL

14 Maximum Participants

Integer

15 Allocation Decimal Cannot be edited.

16 Resource No. Code 20 Relation to table 156 Resource, where Type=Machine

17 Comment Boolean FlowField; checks whether any lines exist on the Comment Line table for the Seminar Room table and the corresponding seminar room code Cannot be edited.

18 Internal/External Option Options: Internal, External

19 Contact No. Code 20 Relation to the Contact table (5050)

• The primary key is Code. After the List page is created for this table, set the LookupFormID property to specify form/page 123456704 as the lookup form/page for this table.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 10: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-10

NOTE: The extended data types are used by the system to associate certain standard built-in actions to certain types of fields. For example, a field that has the extended data type "URL" will have a button displayed next to the field that opens a web browser for the URL entered. In the same way, a field with the extended data type "E-Mail" will have a button displayed next to it that opens a new message for the email address that is entered into the field.

HINT: For all fields, set the Caption value to the Name. To save time, use F8 (Copy Previous shortcut).

4. Use the wizard to create the Seminar Room Card page (123456703) - create the FastTabs as shown in the image "SEMINAR ROOM CARD PAGE (123456703)" in the previous section.

5. From the Page area of the object designer, press F3 to create a new page. Enter "Seminar Room" or the table number 123456702 into the Table textbox to select the right table. Select "Card" as the page type. This will create an empty page object of the type Card.

6. In the first line, enter "Container" as the Type, and "Content Area" as the SubType. This will create the area on the page to display the fields in the Card. Enter a Name for the Container, such as SeminarRoomCardContainer.

7. Next create a line with the value "Group" in both the Type and the SubType, and enter "General" as the name and caption of the group. This will create the General FastTab that holds general Seminar Room fields.

8. Open the Field Menu, select the fields that go into the General FastTab, and then click into the page object. When the system asks for confirmation to add the fields, click "Yes" to accept the fields.

9. Create another Group for the "Communication" FastTab, and enter the correct fields into this FastTab. For the "Phone No." and "E-Mail" fields, set the "Importance" property to "Promoted", so that when the Communication FastTab is minimized, the phone number and email address of the seminar room will always be visible.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 11: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-11

10. Like most other Card pages, the Seminar Room Card page will have a RecordLinks factbox and a Notes factbox, which are standard factboxes provided by the system. A Container of the SubType "FactBoxArea" will be added to place these two factboxes on the page. This Container must be indented all the way to the left. Then add two "Part" type lines to the page, with the PartType property set to "System", and the SystemPartID property set to RecordLinks and Notes respectively. o RecordLinks are references to external files, Web sites, and

more. For instance, an Item record can have a RecordLink to a user manual that is stored as a Word document in a network folder, or a URL can be added to a related Web page. RecordLinks are links which can be clicked that the system will attempt to open with the program that is associated with the type of link that is entered into the RecordLink.

o Notes are part of application-wide functionality to add user defined notes to any record in the database. These notes are associated to the record automatically. Notes can be used for any appropriate purpose.

11. Add the Related Information menu item. Go to the first empty line at the bottom of the page designer and select "Actions" from the view menu. Create the menu as follows:

Type/Subtype Caption Comment

ActionContainer / Related Information

Select the SubType, move the cursor down off the line and move it back up. The Name and Caption will appear automatically with default values.

ActionGroup &Seminar Room

Indented one level under the ActionContainer. Enter the caption, move the cursor down one line and move it back up. The name will appear automatically with a default value.

Action Co&mments Opens the Comment Sheet page (124) for the selected entry. Enter "View Comments" in the Image property. The link between the seminar room and the comment sheet is entered into the RunFormLink property. Link the field "Table Name" to the CONST "Seminar Room". Link the field "No." to the FIELD "Code".

Action E&xtended Texts

Opens the Extended Text page (386) for the selected entry. Link this field the same as above.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 12: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-12

NOTE: The Action Designer Page can only be properly accessed when the first empty line at the bottom of the Page Designer is highlighted. Actions that are defined when the cursor is focusing on a line will not display when the page object runs.

12. Save and compile the page. Test run it by going to the Windows START menu, Click Run, then enter the command:

dynamicsnav:////runpage?page=123456703

The RoleTailored client will open and display the page.

13. Use the wizard to create the Seminar Room List page (123456704) as shown in the GUI design in the image "SEMINAR ROOM LIST (PAGE 123456704)." The only fields necessary on this form are Code, Name, Maximum Participants, and Resource No.

14. Just like the Seminar Room Card page, start with the Page wizard. Select the Seminar Room table and set the Page Type to "List".

15. List pages also need a ContentArea as the first elements, and a Group element of SubType "Repeater". Add the specified fields to the Repeater group.

16. Just as on the Seminar Room Card page, add a FactBoxArea to the list page and include RecordLinks and Notes FactBoxes.

17. Enter "Seminar Room Card" as the CardFormID property. This property links the Seminar Room List page and the Seminar Room Card page together. When the List page is displayed, the user can double-click any record to view the details in the Card page that is specified in the CardFormID property.

18. Add the Related Information menu item as follows:

Type/SubType Options Comments

ActionContainer / RelatedInformation

Action Group &Seminar Room

Action Co&mments Opens the Comment Sheet page (124) for the selected entry.

Action E&xtended Texts

Opens the Extended Texts page (386) for the selected entry.

19. Set the Action links the same as for the Card page. 20. The table and pages are created, but they are not complete. It is

necessary to add some code, mostly for the purposes of data validation which will be done in the next lab.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 13: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-13

Lab 2.2 - Adding Code for Seminar Rooms Within the Seminar Room table, certain fields require validation code in the appropriate triggers to ensure that data entered follows the defined business rules.

Scenario

The functionality of the City and Post Code fields must be enhanced. In Microsoft Dynamics NAV, the Post Code table links cities and post codes. Therefore, write code so that when a user enters a City, the program fills in the corresponding Post Code value from the Post Code table, and vice versa. The existing table, Post Code, has functions that help in doing this.

Challenge Yourself!

Create the Seminar Room Card and List pages like those in the preceding Solution Design.

Step by Step

1. In the Seminar Room table, create a global C/AL variable called PostCode for the record Post Code.

2. Validate the City field using the ValidateCity function from the Post Code table. Use the C/AL Symbol Menu to lookup the parameters for this function and insert the following code in the City - OnValidate trigger:

PostCode.ValidateCity(City,"Post Code");

3. Enter code so that when the user performs a lookup on the City field, the program runs the Post Code table's LookUpCity function. Use the C/AL Symbol Menu to determine what parameters must be sent to the function when calling it. When calling the function, set the ReturnValues parameter to TRUE.

Solution: The City - OnLookup trigger code is as follows:

PostCode.LookUpCity(City,"Post Code",TRUE);

4. Use the Post Code table's ValidatePostCode function to validate the value entered by the user in the Post Code field.

Solution: The Post Code - OnValidate trigger code is as follows:

PostCode.ValidatePostCode(City,"Post Code");

5. Enter code so that when the user performs a lookup on the Post Code field, the program runs the Post Code table's LookUpPostCode function. When calling the function, set the ReturnValues parameter to TRUE.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 14: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-14

Solution: The Post Code - OnLookup trigger code is as follows:

PostCode.LookUpPostCode(City,"Post Code",TRUE);

The next task is to improve the functionality of the Resource No. and Contact No. fields by retrieving information. In the following steps, create code so that when a user enters a Resource No. or a Contact No., if the Name field is empty, it is filled with the Name from the corresponding Resource or Contact record.

6. Create two global record variables, one for the Resource table and one for the Contact table. Standard Microsoft Dynamics NAV naming conventions dictate that these variables be called "Resource" and "Contact" respectively. However, the variable name "Contact" cannot be used because there is already a field by that name in the Seminar Room table. Instead, enter "MyContact" as the name of this variable.

7. Enter code so that when validating the Resource No. entered by the user, if the Name field in the Seminar Room table is empty, the program looks up the Name field in the corresponding Resource record and assigns it to the Name field in the Seminar Room table.

Solution: Enter this code in the Resource No. -OnValidate trigger:

IF Resource.GET("Resource No.") AND (Name = '') THEN Name := Resource.Name;

NOTE: For an expression in the form of Name = '' there is no blank character embedded between the quote marks, unless the instructions direct otherwise.

8. Enter code so that when validating the Contact No. entered by the user, if the Name field in the Seminar Room table is empty, the program looks up the Name field in the corresponding Contact record and assigns it to the Name field in the Seminar Room table.

Solution: Enter this code in the Contact No. - OnValidate trigger:

IF MyContact.GET("Contact No.") AND (Name = '') THEN Name := MyContact.Name;

9. Create two global record variables, one for the Comment Line and one for the Extended Text Header tables.

10. Enter code in the appropriate table trigger so that when a record is deleted, any corresponding records in the Comment Line table are deleted as well.

HINT: Use the DELETEALL function to delete the records.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 15: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-15

Solution: Enter this code in the OnDelete trigger:

CommentLine.RESET; CommentLine.SETRANGE("Table Name",CommentLine."Table Name"::"Seminar Room"); CommentLine.SETRANGE("No.",Code); CommentLine.DELETEALL;

11. Enter code in the appropriate table trigger so that when a record is deleted, any corresponding records in the Extended Text Header table are deleted as well.

HINT: Use the DELETEALL function again, but this time, ensure that the parameter is set to TRUE so that the code in the delete trigger of the Extended Text Header fires. The reason to set the parameter to TRUE for the Extended Text Header, and not for the Comment Line, is that the OnDelete trigger code for the Extended Text Header includes code to delete the associated Extended Text Line records.

Solution: Add this code to the OnDelete trigger:

ExtTextHeader.RESET; ExtTextHeader.SETRANGE("Table Name",ExtTextHeader."Table Name"::"Seminar Room"); ExtTextHeader.SETRANGE("No.",Code); ExtTextHeader.DELETEALL(TRUE);

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 16: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-16

Instructors The next step is to create the instructor data management.

Solution Analysis

The functional requirements in Chapter 1 describe the instructor functionality this way:

"Each seminar is taught by an instructor, who is either a CRONUS employee or a subcontractor. To make use of existing Resource and Contact information, each instructor must be set up either as a Resource or as a Contact associated with a Vendor."

With this information, define how instructors are managed in the module.

Solution Design

According to the analysis of the management of instructor information, create one table for managing the instructors.

Managing instructors is done the same way as managing the seminar rooms. Define them as resources to track their assignments, costs, and prices.

FIGURE 2.5 RELATIONSHIP BETWEEN INSTRUCTORS, RESOURCES, AND CONTACTS

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 17: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-17

Review the pages as they appear when complete, starting with the simplest page, the Instructors page. The Instructors page, as shown in the image, enables the entry of instructor information.

FIGURE 2.6 INSTRUCTORS PAGE (123456705)

Development

The following labs implement the instructor functionality.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 18: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-18

Lab 2.3 - Creating Instructor Tables and Pages As with most enhancements of any consequence, the Seminar module requires multiple master data tables and supporting pages.

Scenario

The Seminar module also requires an Instructor table and a list page to inquire and update the data in that table.

Step by Step

1. Create the Instructor table (123456703) with the following fields:

No. Field Name Type Length Comment 1 Code Code 10 Must not be blank.

2 Name Text 50

3 Internal/External

Option

Options: Internal, External

4 Resource No.

Code 20 Relation to table 156 Resource, where Type=Person.

5 Contact No. Code 20 Relation to the Contact table (5050)

The primary key is the Code field.

NOTE: Specify the contents of the DataCaptionFields property for the table and a Caption property for each field in the table.

2. In the Instructor table, enter code so that when the program validates the value in the Resource No. field, if the Name field in the Instructor record is empty, the program fills it with the Name field from the corresponding Resource record. Do the same for the Contact No. field.

HINT: Similar code was written in the previous lab.

3. Create the Instructors page (123456705) as shown in the GUI design.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 19: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-19

Seminars The next step is to create the seminar data management.

Solution Analysis

The functional requirements in chapter 1 describe the seminar functionality in the following way:

"The CRONUS training department holds several different seminars. Each seminar has a fixed duration, and a minimum and maximum number of participants. In some cases seminars can be overbooked, depending on the capacity of the assigned room. Each seminar can be cancelled if there are not enough participants. The price of each seminar is fixed."

"To take advantage of the current Job functionality in Microsoft Dynamics NAV, each seminar is to be defined as a Job. When a seminar is completed, the seminar is posted as a Job, with additional seminar-specific information."

From this description it is possible to create the following use case:

"When defining a new seminar, seminar managers describe the course details, including information such as the seminar name, duration, price, maximum and minimum number of participants, and a Job code."

As in the analysis of the seminar management process, there must be two tables to manage seminar information. The first table is a setup table where the user can define seminar numbering. The second table is to track the seminar profile information.

FIGURE 2.7 RELATIONSHIP BETWEEN SEMINARS AND OTHER ENTITIES

This description provides the information necessary to design and implement the seminar functionality.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 20: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-20

Solution Design

With the design complete, review how the pages appear when implementation is complete.

The Seminar Setup Card page as shown, in the following image, allows the entry of setup information for the seminar.

FIGURE 2.8 SEMINAR SETUP (PAGE 123456702)

The Seminar Card page, shown in the following image, allows the entry of seminar details. The associated Fact Boxes allow entry of related Links and Notes.

FIGURE 2.9 SEMINAR CARD (PAGE 123456700)

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 21: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-21

The Seminar List page, as shown in the following image, provides an overview of the seminars, but does not allow the underlying Seminar table data to be modified.

FIGURE 2.10 SEMINAR LIST (PAGE 123456701)

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 22: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-22

Lab 2.4 - Creating Seminar Tables and Pages The reality of a development project is an incremental effort to build the complete set of foundation tables and their attendant pages for use first in testing and subsequently in the production environment.

Scenario

Just as in the Lab 2.3 exercise, more tables (Seminar Setup and Seminar) must be created. Any time a new table is created, it is necessary to create at least a list page for data maintenance and display. If the table is a master data table, then generally both a card and list page are required for a full featured set of user tools.

Challenge Yourself!

Create Seminar Setup tables and then create the associated Card page. Create the Seminar table and associated Card and List pages. The GUI designs for the page precede this Lab.

Step by Step

To create the seminar master files and pages, do the following:

1. In the Comment Line table (97), add the option Seminar to the options for the field Table Name. Since the five commas and a new option (Seminar Room) were already added in the first lab in this chapter, it is not necessary to repeat the comma addition here.

2. In the Extended Text Header table 279 and the Extended Text Line table (280), add the option Seminar to the options for the field Table Name.

3. Create Table 123456701 Seminar Setup with the following fields:

No. Field Name Type Length Comment

1 Primary Key Code 10

2 Seminar Nos. Code 10 Relation to 308 No. Series table.

3 Seminar Registration Nos.

Code 10 Relation to 308 No. Series table.

4 Posted Seminar Reg. Nos.

Code 10 Relation to 308 No. Series table.

o Per Microsoft Dynamics NAV standards for setup tables, the key

for this table is the Primary Key field, which is left blank.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 23: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-23

4. Create the Seminar table (123456700) with the following fields:

No. Field Name Type Length Comment

1 No. Code 20 An alternate search field is the Search Name field.

2 Name Text 50

3 Seminar Duration

Decimal Decimal places 0:1

4 Minimum Participants

Integer

5 Maximum Participants

Integer

6 Search Name Code 50

7 Blocked Boolean

8 Last Date Modified

Date Cannot be edited.

9 Comment Boolean FlowField; CalcFormula checks whether lines exist in the Comment Line table for the seminar. Cannot be edited.

10 Job No. Code 20 Relation to table 167 Job.

11 Seminar Price Decimal AutoFormat type is 1.

12 Gen. Prod. Posting Group

Code 10 Relation to table 251 Gen. Product Posting Group.

13 VAT Prod. Posting Group

Code 10 Relation to table 324 VAT Product Posting Group.

14 No. Series Code 10 Cannot be edited. Relation to table 308 No. Series.

o The primary key for this table is the No. field with a secondary

key of Search Name.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 24: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-24

5. In the Seminar table, enter code to perform the following validation tasks: o When the user changes the No. value from what it is previously,

the program gets the Seminar Setup record and uses the TestManual function of the NoSeriesManagement codeunit to test whether the number series is allowed to be manually changed. The program then sets the No. Series field to blank.

HINT: Use the xRec variable to test whether the No. field is modified. To perform this task a record variable is needed with a subtype of Seminar Setup and a Codeunit variable of subtype NoSeriesManagement. Remember that there is only one record in the Seminar Setup table and the primary key field is left null.

Solution:

IF "No." <> xRec."No." THEN BEGIN SeminarSetup.GET; NoSeriesMgt.TestManual(SeminarSetup."Seminar Nos."); "No. Series" := ''; END;

o When the user enters or changes a value in the Name field, if the Search Name is still equal to the uppercase value of the previous Name or if the Search Name is blank, the program assigns the new Name to Search Name.

HINT: Use the function UPPERCASE when testing the Search Name field.

Solution:

IF ("Search Name" = UPPERCASE(xRec.Name)) OR ("Search Name" = '') THEN BEGIN "Search Name" := Name; END;

o When the user enters or changes a value in the Job No. field, the program retrieves the corresponding Job record and checks that the Blocked field is set to <blank>.

HINT: Use the TESTFIELD function to check a field's value.

Solution:

Job.GET("Job No."); Job.TESTFIELD(Blocked, Job.Blocked::" ");

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 25: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-25

o When the user changes the Gen. Prod. Posting Group to a new value, the program checks that the function ValidateVatProdPostingGroup for the Gen. Product Posting Group table returns true. If it does, the program sets the VAT Prod. Posting Group to the Def. VAT Prod. Posting Group value from the Gen. Product Posting Group table.

Solution:

IF xRec."Gen. Prod. Posting Group" <> "Gen. Prod. Posting Group" THEN BEGIN IF GenProdPostingGrp.ValidateVatProdPostingGroup(GenProdPostingGrp,"Gen. Prod. Posting Group") THEN BEGIN VALIDATE("VAT Prod. Posting Group",GenProdPostingGrp."Def. VAT Prod. Posting Group"); END; END;

6. In the Seminar table, create a new function named AssistEdit with a return type of Boolean. In this function, enter code that checks for a Seminar Nos. series in the Seminar Setup table. If it finds one, the program uses the SelectSeries function in the NoSeriesManagement codeunit to check the series number. If this function returns true, the program uses the SetSeries function in the NoSeriesManagement codeunit to set the No. field, and the program then exits TRUE.

Solution:

WITH Seminar DO BEGIN Seminar := Rec; SeminarSetup.GET; SeminarSetup.TESTFIELD("Seminar Nos."); IF NoSeriesMgt.SelectSeries(SeminarSetup."Seminar Nos.",xRec."No. Series","No. Series") THEN BEGIN SeminarSetup.GET; SeminarSetup.TESTFIELD("Seminar Nos."); NoSeriesMgt.SetSeries("No."); Rec := Seminar; EXIT(TRUE); END; END;

7. In the Seminar table, enter code in the appropriate table triggers to perform the following tasks: o Document the code. o When a record is inserted, if the No. field is blank, the program

gets the Seminar Setup record and runs the InitSeries function of the NoSeriesManagement codeunit to initialize the series.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 26: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-26

Solution: Enter the following code in the OnInsert trigger:

IF "No." = '' THEN BEGIN SeminarSetup.GET; SeminarSetup.TESTFIELD("Seminar Nos."); NoSeriesMgt.InitSeries(SeminarSetup."Seminar Nos.",xRec."No. Series",0D,"No.","No. Series"); END;

o When a record is modified or renamed, the program sets the Last Date Modified to the current date.

HINT: Use the TODAY function to get the current date.

Solution: Enter the following code in the OnModify and OnRename triggers:

"Last Date Modified" := TODAY;

o When a record is deleted, the program deletes the corresponding records from the Comment Line table and the Extended Text Header table.

HINT: Similar code was created for the Seminar Room comment and extended text records.

8. Create the Seminar Setup page (123456702) as shown in the GUI design.

9. Enter code in the appropriate trigger of the Seminar Setup page so that when the user opens the form, the program resets the record, and if it does not get a record, it inserts a new one.

Solution: Enter the following code in the Page - OnOpenPage trigger:

RESET; IF NOT GET THEN INSERT;

10. Create the page 123456700 Seminar Card as shown in the GUI design. o Set the property to update the page when it is activated. o Add the Related Information menu item as follows:

Type/SubType Options Comment

ActionContainer / RelatedInformation

Enter a reference name such as SeminarCardSetupContainer

ActionGroup &Seminar

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 27: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-27

Type/SubType Options Comment

Action Co&mments

Opens the Comment Sheet page (124) for the selected entry.

Action E&xtended Texts

Opens the page 386 Extended Texts for the selected entry.

Solution: Enter the following code in the No. - OnAssistEdit trigger:

IF AssistEdit THEN CurrPage.UPDATE;

o Enter code in the appropriate trigger so that after the page gets the record, the program removes the table's filter on the No. field.

11. Create the Seminar List page (123456701) according to the GUI Design section. Include the fields No., Name, Seminar Duration, Minimum Participants (not visible), Maximum Participants (not visible), Seminar Price, Gen. Prod. Posting Group, VAT Prod. Posting Group, and Job No. o Make the page so that it cannot be edited. o The navigation from this page is the same as the Seminar Card

page, so add the same options to the Actions menu as the actions on the Seminar Card.

HINT: Line items and action items can be copied from one page to another.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 28: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-28

Testing With the master tables and pages in place, it is critical that the functionality is tested. To this end, a test script can be used. Because not all solution pieces are coded, the test script may seem incomplete at this point.

Since none of the pages are set up in a Role Center, the pages will be tested from the command prompt, as described in the test script steps.

NOTE: To test the Email functionality, the system that is being used must have Microsoft® Outlook® running with a profile set up.

Steps

1. Start by running the page 123456702 Seminar Setup from the Run command. Click the Start button and select "Run." Enter Dynamicsnav:////runpage?page=123456702, and click OK. The fields in this page are blank because they are not yet set up. Select "Edit" from the "Actions" menu so the page can be edited. Click the drop-down list for Seminar Nos. Seminars are now setup to use the standard Microsoft numbering functionality. o Set up all three numbers by choosing any values. o Set to Default automatically o Close and re-open the Seminar Setup page to verify that the

values are saved.

2. Run the page 123456700 Seminar Card from the Run command. o If the page opens on an existing Seminar record, select "New"

from the "Actions" menu or use the 'Ctrl + N' shortcut keys to open the page with a new record.

o Tab off the No. field and be sure that a number is assigned with the values that are set up in step 1.

o Fill in the fields under the General FastTab and then move to the Invoicing FastTab.

o Use the dropdown to select a Gen. Prod. Posting Group that has a Default VAT Prod. Posting Group set up.

o When selecting this record, be sure that the VAT Prod. Posting Group fills in automatically.

3. On the Seminar Card page, use the Related Information menu to enter comments and extended texts. When finished, close the Seminar Card page.

4. Run the page 123456701 Seminar List from the Run command, Dynamicsnav:////runpage?page=123456701. Doubleclick on an existing record and verify that the Seminar Card page opens up in Edit mode, with the selected record.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 29: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-29

5. The Seminar module is now designed so that Instructors are set up as Resources and Contacts in the system. o Set up a new Resource (type Person) and Contact to use to test

the Instructor functionality. o When done, run the page 123456705 Instructors from the Run

command. o Enter a new instructor using the Internal/External Option in

combination with the Resource and Contact lookup buttons to select the Resource and Contact set.

o Note that when using the Resource lookup, all the Resources in the list are of type Person. Try entering a Resource No. or Contact No. that does not exist to test the validation.

o When you have finished close the Instructors page. 6. The Seminar module is now designed so the Rooms are set up as

Resources of type Machine and Contacts in the system. o Set up a new Resource and Contact to test the Seminar Room

functionality. o When finished, run the page 123456703 Seminar Room Card

from the Run command. o If the page opens up with an existing record, select "New" from

the "Actions" menu and verify that the Seminar Room page opens up with a new blank record.

o Create a new Seminar Room by entering a value in the Code field.

7. Code is added so that the Name field defaults from the Resource or Contact if the Name field is blank. o Ensure that code is functioning. o On the Communications tab, try entering an E-Mail address and

Home Page and use the command buttons next to them. o Check the items on the "Related Information" menu.

8. Run the page 123456704 Seminar Room List from the Run

command and ensure that the Seminar Room Card page opens up when double-clicking on the existing Seminar Room record on the List page.

Summary In this chapter, two of the most fundamental object types, tables and pages, are used to put the foundation for the solution in place. The tables define and store the data for the solution, and the pages provide an intuitive interface with which the user can interact with the table data.

Defining the tables requires analysis of the relationships between the entities represented by each table. Implementation of the tables is easier if the simpler tables, those with fewer dependencies, are defined first.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 30: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-30

Test Your Knowledge

1. Where is internal documentation located for new objects?

2. To ensure that Microsoft Dynamics NAV's multilanguage functionality is properly enabled, which property must be set for controls?

3. In the Seminar table, a check is performed to ensure that the value in the Minimum Participants field is always less than the value in the Maximum Participants field in each of the following situations:

• Whenever a record is inserted. • Whenever a record is changed. • Whenever a value is entered in the Maximum Participants field and

the Minimum Participants field is not empty.

4. a) Which table and field event triggers are used for these three checks?

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 31: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-31

5. b) What code is used to perform these checks?

6. What do the Rec and xRec record variables do?

7. What function is used to retrieve a specific record using its primary key?

8. Using the table shown below, answer the following questions:

Table: Employee (key = Employee No.)

Employee No. Name Department 5834 John Doe Purchasing 3723 Ann Smith Sales 3475 Bill Skaggs Receivables 6434 Todd Lawrence Sales

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 32: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-32

Employee No. Name Department 9482 Janet Davila Receivables 0980 Susan Morris Purchasing 9483 Rick Hamilton Sales

a) Assuming that work is being performed with the record variable EmployeeVar, what code needs to be written to get the record for Employee No. 3475?

b) What code can be written to jump to the fourth next record?

c) What code can be written to jump to the last record in the table?

d) What code is used to define a record set to include the records between employee number 3475 and 6434?

e) What code is used to define a record set to include the records greater than 5834?

f) What code is used to define a record set for employees in the Purchasing department only?

g)What code is used to remove the filter on department?

h) What code is used to change Ann Smith's department from Sales to Purchasing?

i) What code is used to delete all Receivables employees?

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 33: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-33

9. What is the standard way to associate a Card page with a List page?

10. What two triggers does a Codeunit have by default?

11. How are functions and access to related tables defined on pages?

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 34: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-34

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

Page 35: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-35

Solutions Test Your Knowledge

1. Where is internal documentation located for new objects?

MODEL ANSWER:

Internal documentation for new objects is located in the Documentation trigger, which is available in every object. Comments can be entered in this trigger without having to enter them as code remarks.

2. To ensure that Microsoft Dynamics NAV's multilanguage functionality is properly enabled, which property must be set for controls?

MODEL ANSWER:

The CaptionML property is used to define multi-language captions, one for each language that the user can select.

3. In the Seminar table, a check is performed to ensure that the value in the Minimum Participants field is always less than the value in the Maximum Participants field in each of the following situations:

• Whenever a record is inserted. • Whenever a record is changed. • Whenever a value is entered in the Maximum Participants field and

the Minimum Participants field is not empty.

4. a) Which table and field event triggers are used for these three checks?

5. b) What code is used to perform these checks?

MODEL ANSWER:

a) In the OnValidate trigger of each relevant field and in the OnInsert and OnModify triggers of the table. It is best to create a new function that checks the values and enter a call to this function in the relevant table triggers. b) The suggested code is in the form of a Function named MinMaxParticipantsCheck MinMaxParticipantsCheck IF ("Minimum Participants" <> 0) AND NOT ("Maximum Participants" > "Minimum Participants") THEN ERROR(Text500);

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 36: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-36

6. What do the Rec and xRec record variables do?

MODEL ANSWER:

The Rec record variable specifies the values of the current record, including the changes that are made. The xRec record variable specifies the original values of the record, before the changes.

7. What function is used to retrieve a specific record using its primary key?

MODEL ANSWER:

To retrieve a function using its primary key, the GET function is used.

8. Using the table shown below, answer the following questions:

Table: Employee (key = Employee No.)

Employee No. Name Department 5834 John Doe Purchasing 3723 Ann Smith Sales 3475 Bill Skaggs Receivables 6434 Todd Lawrence Sales 9482 Janet Davila Receivables 0980 Susan Morris Purchasing 9483 Rick Hamilton Sales

a) Assuming that work is being performed with the record variable EmployeeVar, what code needs to be written to get the record for Employee No. 3475?

b) What code can be written to jump to the fourth next record?

c) What code can be written to jump to the last record in the table?

d) What code is used to define a record set to include the records between employee number 3475 and 6434?

e) What code is used to define a record set to include the records greater than 5834?

f) What code is used to define a record set for employees in the Purchasing department only?

g)What code is used to remove the filter on department?

h) What code is used to change Ann Smith's department from Sales to Purchasing?

i) What code is used to delete all Receivables employees?

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 37: Na2009 enus devii_02

Chapter 2: Master Tables and Pages

2-37

MODEL ANSWER:

a) EmployeeVar.GET('3475'); b) EmployeeVar.NEXT(4); c) EmployeeVar.FINDLAST; d) EmployeeVar.SETRANGE("No.",'3475','6434'); e) EmployeeVar.SETFILTER("No.",'>5834"); f) EmployeeVar.SETRANGE("Global Dimension 1 Code",'PURCHASE'); (NOTE: This code assumes that Global Dimension 1 is used for DEPARTMENT, and that the value PURCHASE is the value for the purchasing department.) g) EmployeeVar.SETRANGE("Global Dimension 1 Code"); h) EmployeeVar.GET('ANNSMITH');// assuming that is her No. EmployeeVar.VALIDATE("Global Dimension 1 Code",'PURCHASE'); EmployeeVar.MODIFY(TRUE); i) EmployeeVar.SETRANGE("Global Dimension 1 Code",'RECEIVABLES'); EmployeeVar.DELETEALL;

9. What is the standard way to associate a Card page with a List page?

MODEL ANSWER:

The standard way to associate a Card page with a List page is by setting the "CardFormID" property on the List page.

10. What two triggers does a Codeunit have by default?

MODEL ANSWER:

Documentation and OnRun

11. How are functions and access to related tables defined on pages?

MODEL ANSWER:

Functions and access to related tables are defined on pages by defining the selections in the Actions menu, which can be accessed by moving the cursor to the first available empty line in the page designer and then selecting "Actions" from the View menu. The Type of the action defined as "ActionContainer" and the Subtype of the action is defined as any of the available system values, depending on where the action needs to be on the page.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 38: Na2009 enus devii_02

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

2-38

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement