Navision 2009 - CSide Introduction

download Navision 2009 - CSide Introduction

of 552

description

yutyutuyt

Transcript of Navision 2009 - CSide Introduction

  • MICROSOFT DYNAMICS NAV 2009

    C-SIDE INTRODUCTION

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

  • Last Revision: December 2008 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. 2008 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

    i

    Introduction 0-1 Welcome ............................................................................................................ 0-1 Microsoft Dynamics Courseware Contents ........................................................ 0-2 Documentation Conventions .............................................................................. 0-3 Student Objectives ............................................................................................. 0-4

    Chapter 1: Client/Server Integrated Development Environment (C/SIDE) 1-1

    Objectives ........................................................................................................... 1-1 Introduction ......................................................................................................... 1-1 Basic Objects in Microsoft Dynamics NAV ......................................................... 1-2 C/SIDE Fundamentals ........................................................................................ 1-3 The Physical and the Logical Database ............................................................. 1-8 Integration Tools ............................................................................................... 1-10 Summary .......................................................................................................... 1-12 Quick Interaction: Lessons Learned ................................................................. 1-13

    Chapter 2: Tables 2-1 Objectives ........................................................................................................... 2-1 Introduction ......................................................................................................... 2-1 Table Fundamentals ........................................................................................... 2-2 Primary and Secondary Keys ........................................................................... 2-10 Demonstration: Create a Simple Table ............................................................ 2-12 Table Relationships .......................................................................................... 2-17 Demonstration: Table Relations ....................................................................... 2-21 Special Table Fields ......................................................................................... 2-29 Demonstration: Special Table Fields ................................................................ 2-31 Table Types and Characteristics ...................................................................... 2-41 Lab 2.1 - Create a Table .................................................................................. 2-53 Summary .......................................................................................................... 2-57 Test Your Knowledge ....................................................................................... 2-58 Quick Interaction: Lessons Learned ................................................................. 2-59

    Chapter 3: Forms 3-1 Objectives ........................................................................................................... 3-1 Introduction ......................................................................................................... 3-1 Form Fundamentals ........................................................................................... 3-2 Demonstration: Create a Simple Form ............................................................... 3-8 Form Types and Characteristics....................................................................... 3-24 Demonstration: Create a Card Form ................................................................ 3-34 Demonstration: Create a List Form .................................................................. 3-39 Demonstration: Link the Card Form and the List Form .................................... 3-41 Demonstration: Form and Subform .................................................................. 3-45 Lab 3.1 - Create a Card and a List Form .......................................................... 3-48 Standard Navigation ......................................................................................... 3-51 Summary .......................................................................................................... 3-53 Test Your Knowledge ....................................................................................... 3-54 Quick Interaction: Lessons Learned ................................................................. 3-55

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 20099

    ii

    Chapter 4: Pages 4-1 Objectives ........................................................................................................... 4-1 Introduction ......................................................................................................... 4-1 Page Fundamentals ........................................................................................... 4-2 Page Designer .................................................................................................... 4-8 Demonstration: Create a Simple Page ............................................................. 4-13 Page Types and Characteristics....................................................................... 4-25 Design Pages: Best Practices .......................................................................... 4-34 Demonstration: Create a Card Page ................................................................ 4-35 Demonstration: Create a List Page .................................................................. 4-38 Demonstration: Page and Part Page ................................................................ 4-39 Lab 4.1 - Create a Card, a List and a ListPart Page......................................... 4-42 Summary .......................................................................................................... 4-45 Quick Interaction: Lessons Learned ................................................................. 4-46

    Chapter 5: Introduction to C/AL Programming 5-1 Objectives ........................................................................................................... 5-1 Introduction ......................................................................................................... 5-1 C/AL Programming ............................................................................................. 5-2 Intrinsic Data Types ............................................................................................ 5-5 Identifiers, Variables and Syntax ...................................................................... 5-13 The Syntax of Identifiers ................................................................................... 5-14 Variable Scope ................................................................................................. 5-14 Variable Initialization ........................................................................................ 5-15 Demonstration: Data Types and Variables Initialization ................................... 5-15 Lab 5.1 - Investigate Data Types...................................................................... 5-20 Summary .......................................................................................................... 5-22 Test Your Knowledge ....................................................................................... 5-23 Quick Interaction: Lessons Learned ................................................................. 5-24

    Chapter 6: Assignment Statements and Expressions 6-1 Objectives ........................................................................................................... 6-1 Introduction ......................................................................................................... 6-1 Assignment Statements ..................................................................................... 6-2 The Syntax of Statements .................................................................................. 6-2 Automatic Type Conversions.............................................................................. 6-4 Demonstration: Use Assignment Statements and the Symbol Menu ................. 6-5 Expressions, Terms, and Operators ................................................................... 6-9 The Syntax of an Expression ........................................................................... 6-11 The String Operator .......................................................................................... 6-11 Demonstration: Use the String Operator .......................................................... 6-12 Function Calls in Expressions .......................................................................... 6-13 Demonstration: Use the MAXSTRLEN and the COPYSTR Function ............... 6-14 Numeric Expressions ....................................................................................... 6-16 Arithmetic Operators ........................................................................................ 6-16 Demonstration: Use the Arithmetic Operators .................................................. 6-21 Relational and Logical Expressions.................................................................. 6-24 Relational Expressions for Comparison ........................................................... 6-25 Relational Expressions for Set Inclusion .......................................................... 6-27 Logical Expressions ......................................................................................... 6-28

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

  • Table of Contents

    iii

    Demonstration: Use Logical and Relational Expressions in a Page ................. 6-30 Summary .......................................................................................................... 6-33 Test Your Knowledge ....................................................................................... 6-34 Quick Interaction: Lessons Learned ................................................................. 6-35

    Chapter 7: C/AL Statements 7-1 Objectives ........................................................................................................... 7-1 Introduction ......................................................................................................... 7-1 Conditional Statements and Boolean Expressions............................................. 7-2 The IF Statement ................................................................................................ 7-2 The EXIT Statement ........................................................................................... 7-4 The CASE Statement ......................................................................................... 7-5 Compound Statements and Comments ............................................................. 7-6 The Syntax of Compound Statements ............................................................... 7-6 Compound Statement by Using Nested IF Statements ...................................... 7-8 The Syntax of Comments ................................................................................. 7-10 Demonstration: Use the IF, EXIT, CASE and Compound Statements in a Page7-11 Test Your Knowledge ....................................................................................... 7-20 Lab 7.1 - Use Conditional and Compound Statements .................................... 7-21 Arrays ............................................................................................................... 7-25 The Syntax of Arrays ........................................................................................ 7-26 The Power of Arrays ......................................................................................... 7-28 Strings as Arrays of Characters ........................................................................ 7-29 Repetitive Statements ...................................................................................... 7-30 Demonstration: Use Arrays and Repetitive Statements ................................... 7-35 The WITH Statement ........................................................................................ 7-45 Summary .......................................................................................................... 7-47 Test Your Knowledge ....................................................................................... 7-48 Quick Interaction: Lessons Learned ................................................................. 7-49

    Chapter 8: C/AL Functions 8-1 Objectives ........................................................................................................... 8-1 Introduction ......................................................................................................... 8-1 Functions and Parameters ................................................................................. 8-2 Review Built-in Functions ................................................................................... 8-3 Demonstration: Use the DATE2DMY Function .................................................. 8-8 Test Your Knowledge ......................................................................................... 8-9 Essential C/AL Functions ................................................................................. 8-10 User Communication Functions ....................................................................... 8-19 String Functions ............................................................................................... 8-22 System Functions ............................................................................................. 8-25 Date Functions ................................................................................................. 8-28 Number Functions ............................................................................................ 8-31 Array Functions ................................................................................................ 8-32 Other Functions ................................................................................................ 8-34 Create Custom Functions ................................................................................. 8-38 Formal and Actual Parameters ......................................................................... 8-39 Local Functions, Variables and the EXIT Statement ........................................ 8-40 Demonstration: Create Custom Functions ....................................................... 8-41 Summary .......................................................................................................... 8-45

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 20099

    iv

    Test Your Knowledge ....................................................................................... 8-46 Quick Interaction: Lessons Learned ................................................................. 8-47

    Chapter 9: Reports 9-1 Objectives ........................................................................................................... 9-1 Introduction ......................................................................................................... 9-1 Reports Fundamentals ....................................................................................... 9-2 Types of Printing Reports ................................................................................... 9-7 Report Design Process ...................................................................................... 9-9 Design the Data Model ..................................................................................... 9-11 Demonstration: Create a Data Model ............................................................... 9-12 Design the Visual Element ............................................................................... 9-15 Demonstration: Design the Report Section ...................................................... 9-17 Demonstration: Modify Report Properties ........................................................ 9-27 Demonstration: Design the Report Layout ....................................................... 9-31 The Request Options Designer ........................................................................ 9-40 Demonstration: Design the Request Options Form .......................................... 9-41 Demonstration: Design the Request Options Page .......................................... 9-44 Grouping Within a Classic Report .................................................................... 9-47 Demonstration: Create Grouping For The Classic Report ................................ 9-48 Totaling in a Report .......................................................................................... 9-51 Demonstration: Create Totals For The Classic Report ..................................... 9-52 Demonstration: Create Grouping and Totals For The RoleTailored Report ..... 9-54 Demonstration: Add Some Advanced Features ............................................... 9-59 Lab 9.1 - Create a Basic Report ....................................................................... 9-67 Summary .......................................................................................................... 9-70 Test Your Knowledge ....................................................................................... 9-71 Quick Interaction: Lessons Learned ................................................................. 9-72

    Chapter 10: Dataports and XMLports 10-1 Objectives ......................................................................................................... 10-1 Introduction ....................................................................................................... 10-1 Dataport Fundamentals .................................................................................... 10-2 Design Dataports .............................................................................................. 10-4 Demonstration: Create Dataports For Export ................................................... 10-8 Demonstration: Create Dataports For Import ................................................. 10-14 XMLPort Fundamentals .................................................................................. 10-17 Design XMLports ............................................................................................ 10-21 Demonstration: Create XMLports For Use In The Classic Client ................... 10-26 Demonstration: Create XMLports For Use In The RoleTailored Client .......... 10-33 Lab 10.1 - Create XMLports ........................................................................... 10-36 Summary ........................................................................................................ 10-40 Test Your Knowledge ..................................................................................... 10-41 Quick Interaction: Lessons Learned ............................................................... 10-42

    Chapter 11: Codeunits 11-1 Objectives ......................................................................................................... 11-1 Introduction ....................................................................................................... 11-1 Codeunit Fundamentals ................................................................................... 11-2 Design Codeunits ............................................................................................. 11-3

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

  • Table of Contents

    v

    Use Codeunits .................................................................................................. 11-4 Demonstration: Define Variables, Text Constants and Functions in a Codeunit11-6 SMTP ............................................................................................................... 11-7 Summary .......................................................................................................... 11-9 Test Your Knowledge ..................................................................................... 11-10 Quick Interaction: Lessons Learned ............................................................... 11-11

    Chapter 12: MenuSuites 12-1 Objectives ......................................................................................................... 12-1 Introduction ....................................................................................................... 12-1 MenuSuite Fundamentals................................................................................. 12-2 Create and Design MenuSuites........................................................................ 12-2 Upgrade MenuSuite ......................................................................................... 12-6 Demonstration: Create a MenuSuite For The Classic Client ............................ 12-7 Demonstration: Create A MenuSuite For The RoleTailored Client ................... 12-9 Lab 12.1 - Create MenuSuites ....................................................................... 12-12 Summary ........................................................................................................ 12-14 Test Your Knowledge ..................................................................................... 12-15 Quick Interaction: Lessons Learned ............................................................... 12-16

    Chapter 13: Integration Options 13-1 Objectives ......................................................................................................... 13-1 Introduction ....................................................................................................... 13-1 Web Services ................................................................................................... 13-2 Demonstration: Create, Expose and Consume Web Services ......................... 13-6 ODBC ............................................................................................................. 13-18 Demonstration: Use Microsoft Dynamics NAV ODBC .................................... 13-22 C/FRONT ....................................................................................................... 13-25 OCX ................................................................................................................ 13-27 Demonstration: Use OCX Controls................................................................. 13-29 Automation Server .......................................................................................... 13-32 Demonstration: Create a Report with Automation .......................................... 13-35 Summary ........................................................................................................ 13-40 Test Your Knowledge ..................................................................................... 13-41 Quick Interaction: Lessons Learned ............................................................... 13-42

    Appendix A: Solutions to Exercises A-1 Test Your Knowledge Answers (CH2) ............................................................... A-1 Test Your Knowledge Answers (CH3) ............................................................... A-3 Test Your Knowledge Answers (CH5) ............................................................... A-4 Test Your Knowledge Answers (CH6) ............................................................... A-6 Test Your Knowledge Answers (CH7 Part 1) .................................................... A-8 Test Your Knowledge Answers (CH7 Part 2) .................................................... A-9 Test Your Knowledge Answers (CH7 Part 2) .................................................... A-9 Test Your Knowledge Answers (CH8 Part 1) .................................................. A-11 Test Your Knowledge Answers (CH8 Part 2) .................................................. A-13 Test Your Knowledge Answers (CH9) ............................................................. A-14 Test Your Knowledge Answers (CH10) ........................................................... A-16 Test Your Knowledge Answers (CH11) ........................................................... A-18 Test Your Knowledge Answers (CH12) ........................................................... A-19

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 20099

    vi

    Test Your Knowledge Answers (CH13) ........................................................... A-20

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

  • Introduction

    0 - 1

    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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    0 - 2

    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.

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

  • Introduction

    0 - 3

    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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    0 - 4

    Student Objectives What do you hope to learn by participating in this course? List three main objectives below. 1.

    2.

    3.

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

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-1

    CHAPTER 1: CLIENT/SERVER INTEGRATED DEVELOPMENT ENVIRONMENT (C/SIDE) Objectives

    The objectives are:

    Discuss Basic Objects in Microsoft Dynamics NAV 2009. Describe fundamental aspects of C/SIDE development, including the

    UI, application objects, C/SIDE concepts, and the types of databases. Discuss the database structure. Describes some integration tools and advanced development

    concepts.

    Introduction The starting point to learn developing solutions in Microsoft Dynamics NAV 2009 is to understand the basic objects available in Microsoft Dynamics NAV, understand the Client / Server Integrated Development Environment (C/SIDE, which is the development environment for Microsoft Dynamics NAV) fundamentals and understand the concepts of the database structure.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-2

    Basic Objects in Microsoft Dynamics NAV There are eight basic objects available in Microsoft Dynamics NAV 2009, they are as follows:

    Object Description Tables Used to describe how data is stored in the database and how it is

    retrieved. Understanding tables is the key to using all of the other objects in C/SIDE.

    Forms Used to display data to users in the Microsoft Dynamics NAV Classic client. Forms allow users to add records to a table, and to view and modify records.

    Pages Used to display data to users in the Microsoft Dynamics NAV RoleTailored client. Pages allow users to add records to a table, and to view and modify records.

    Reports Used to summarize and print detailed information by using filters and sorting, which are selected by the users.

    Dataports Used to export or import table data in text format. Not supported in the RoleTailored client.

    XMLports Used to export or import table data in XML format. In the RoleTailored client, XMLports replace Dataports as a means to export and import data, even in text format.

    Codeunits Used to organize and group code which is written by the developers.

    MenuSuites Used to contain menus that are displayed in the Navigation Pane in the Classic client and the Departments page in the RoleTailored client.

    Is Microsoft Dynamics NAV Object Oriented?

    Microsoft Dynamics NAV is not object-oriented but object-based. This is an important distinction. In an object-oriented language or environment, developers can create new types of objects based on the ones that are already in the system. In C/SIDE, developers have eight types of application objects and that is all. Developers can create and use Tables, Forms, Pages, Reports, Dataports, XMLports, Codeunits, and MenuSuites, but nothing else.

    Limiting developers to use these eight objects makes their work faster and more efficient. The biggest benefit from this limitation is stability. It is fairly difficult to create a severe bug in C/SIDE.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-3

    C/SIDE Fundamentals A C/SIDE application is composed of the eight types of application objects, which are described in the previous lesson. Each application object is created using a specific designer. For example, tables are created with the Table Designer, pages are created with the Page Designer, and so on.

    FIGURE 1.1 THE CLASSIC CLIENT WITH TABLE DESIGNER OPENED

    The application objects which are created by using designers are all based on several general concepts. A fundamental knowledge of these concepts speeds up the C/SIDE application development process.

    C/SIDE User Interface

    C/SIDE is accessed from the Classic client. The C/SIDE user interface is composed of the following:

    Object Designer, which contains designers for each of the eight object types.

    Navigation Pane Designer, which is used to arrange MenuSuites on the Navigation Pane.

    Various Tools and Editors, including a Toolbox for adding controls to forms, a C/AL Editor for editing code, a Properties window, a Debugger, and other tools and editors.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-4

    The user interface gives access to a number of tools and functions. Some parts of the user interface also provide information about the current state of the system.

    To... Use the... Get information about the name and path of the current database Title Bar

    Access functions on drop-down menus Menu Bar

    Access the frequently used functions Toolbar

    Work with the application design tools Work Area

    View basic status information about the system (such as the current date and user ID)

    Status Bar

    Depending on the task the users are working on, the system automatically changes the menus and icons in the Menu Bar and the Toolbar.

    Design Application Objects

    Any application designed in C/SIDE is based on the eight different types of application objects available through the Object Designer.

    Tables are the fundamental objects that store the actual data. Other application objects are needed to insert, modify, delete, or view data from tables. A form or a page is typically used to enter or retrieve data from the database and a report is used to print data.

    NOTE: All application objects are identified by an ID number. There are, however, restrictions about which numbers can be used when creating application objects.

    In the Object Designer, select the type of application object to work on. The following can be done from the Object Designer:

    Run an application object (except for page, XMLport and MenuSuite objects.)

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

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-5

    Open the application object designer to modify an existing object. Create a new application object.

    FIGURE 1.2 THE OBJECT DESIGNER

    The following table lists the tools that are accessed from the Object Designer and when to use them.

    Use the When working on Table Designer Tables

    Form Designer Forms

    Page Designer Pages

    Report Designer Reports

    Dataport Designer Dataports

    XMLport Designer XMLports

    C/AL Editor Codeunits

    Navigation Pane Designer MenuSuites

    There is a specific designer for each type of application object. When creating or modifying an application, developers can work on any number of application objects at the same time, and each application object is shown in its own designer. For example, if a developer works on three pages at the same time, each page is displayed in its own Page Designer. The Navigation Pane Designer is the only designer that cannot have more than one instance running at a time.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-6

    General C/SIDE Concepts

    The eight application object types are based on some general concepts. Some of these concepts are restricted to one type of application object whereas others apply to several types.

    The following table summarizes how the application objects are related to these general concepts and explains for what each type of application object is used.

    Application Object Type

    Uses Concepts

    Table A table is used for storing the actual data. Typically a business application has a Customer table that stores information such as name, address, phone number, and contact person for each customer.

    Properties, Fields, Field Groups, Keys, C/AL, Triggers

    Form A form is used to access the information contained in tables in the Classic client. Forms are used when users enter new information and when they view existing information.

    Properties, C/AL, Controls, Triggers

    Page A page is used to access the information contained in tables in the RoleTailored client. Pages are used when users enter new information and when they view existing information.

    Properties, C/AL, Controls, Triggers

    Report A report is used to present data that contains summary information. For example, use a report to print a list of customers.

    Properties, C/AL, DataItems, Sections, Controls, Triggers, RequestForm, RequestPage, Client Report Definition ( RDLC) report layout

    Dataport A dataport is used to import and export information to and from other programs in a text format (for example, a comma-separated text file). Dataports are used only in the Classic client.

    Properties, C/AL, DataItems, RequestForm, Triggers

    XMLport An XMLport is used to import and export information to and from other programs in an XML format. XMLports simplify and streamline the process of exchanging data in XML documents. In the RoleTailored client, XMLports are also used to import and export

    Properties, C/AL, NodeNames, NodeTypes, XMLport Events, RequestPage

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-7

    information in a text format.

    Codeunit A codeunit contains user-defined functions written in C/AL code. These functions can be used from the other objects in the application. This minimizes the size of the application because the same code can be reused.

    C/AL, Triggers

    MenuSuite A MenuSuite contains the menus displayed in the Navigation Pane and in the Departments Page.

    Menu Node, Menu Group, Menu Item

    Terminologies

    The following shows descriptions of several terms in the third column:

    Properties: Properties control the appearance and behavior of application objects and all sub-objects. Properties are used to control the appearance of data, specify default values, specify colors, and define relationships.

    C/AL: C/AL is the language used for writing functions in C/SIDE. In the previous table, C/AL refers to functions written in this language.

    Triggers: When specific things happen to the application objects, the system automatically activates a trigger. Inside a trigger, developers can add C/AL code if they want to modify the default behavior of the application object or extend its functionality.

    Fields: A field is the smallest unit of information in the database. A field typically stores information such as a name or a number.

    Keys: A key defines the order in which data is stored in the tables. Speed up searches in tables by defining several keys to sort information in different ways.

    Controls: Controls are objects on a form or report that display data, perform actions or decorate the form. Typical examples are command buttons and text labels.

    Request Form: A request form is a form used in a report or a dataport. Before a report or a dataport is run, a request form appears to let the user specify filters and options for the report or the dataport.

    Request Page: A request page is the request form equivalent in the RoleTailored client.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-8

    Data Items: A data item is a building block used for defining a model of data when creating a report or a dataport. By using a hierarchy of data items, developers define which data to include in the report. A data item represents a table and when a report is run, the system cycles through the records in the associated table. In a report, a data item can have one or more sections.

    Sections: A section is a substructure of a data item. A section is where controls are placed to display information. Generally, sections are used to define the body, header, and footer in the report.

    NodeName: NodeNames are used to specify the name of a node in an XML document. The name specified is inserted in the NodeName field of the XMLport Designer of the element or attribute in question.

    NodeTypes: This property is used to specify whether an XML object is an element or an attribute.

    Menu Node: A Menu Node can be either a Menu Group or a Menu Item.

    Menu Group: A Menu Group is a collection of Menu Nodes.

    Menu Item: A Menu Item is the lowest level of the menu tree. It is associated with a specific application object.

    The Physical and the Logical Database Typical database users are not concerned with where each piece of data is stored on the hard disk or what its size is; they just want to be sure that when they refer to a name, the correct value is returned. This is why the C/SIDE database system provides a conceptual representation of data that does not include too many details about how the data is stored. An abstract data model is used for this conceptual representation. This data model uses logical concepts (such as objects, their properties, and their relations) that are easier to understand.

    Therefore, it is helpful to distinguish between the logical and the physical database. When speaking about the logical database, only be concerned with the structure of the data and the relationships between different bits of information. That is, users do not deal with how these structures and relations are implemented. The physical database deals with how the structures in the logical database and the search paths between them are implemented.

    When the term database is used, it generally refers to the logical database unless otherwise noted.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-9

    What is visible to the user as a coherent set of information in the C/SIDE database system can be stored in several physical disk files, but this is transparent to the user. The following figure illustrates how one logical database can be physically stored on three hard disks but still comprise a single (logical) database.

    FIGURE 1.3 ILLUSTRATION OF LOGICAL VERSUS PHYSICAL DATABASE

    Access to the data is made possible by a well-defined logical organization composed of:

    Fields Records Tables Companies

    Fields

    A field is the smallest logical structure used in the C/SIDE database. A field is used to hold a single bit of information, such as a name or an amount. Any particular field can hold information of only one specific type.

    Fields are assembled into a structure called a record. On its own, a field is not useful as it can hold only a limited amount of information. Having these small bits of information assembled into records results in a much more flexible "information-holder" that is also better organized because it groups fields that belong together.

    Records

    A record is a logical structure assembled from an arbitrary number of fields; it is used to store a single entry in the database. The fields in a record are used to store information about important properties of the entry. Records are organized in tables.

    Tables

    A table can be thought of as an N times M matrix. Each of the N rows describes a record and each of the M columns describes a field in the record. Tables are organized in companies.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-10

    Companies

    A company is the largest logical structure used in a C/SIDE database. A company may be considered as a sub-database; its primary use is to separate and group large portions of data in a database. A company can contain private tables and tables that are shared with other companies.

    FIGURE 1.4 RELATIONSHIP OF LOGICAL DATABASE STRUCTURE

    Integration Tools Microsoft Dynamics NAV 2009 provides several integration tools that can be used inside or outside of Microsoft Dynamics NAV to integrate to other applications.

    Web Services

    Web services are a standardized way for independent software systems to communicate with one another over standard Internet protocols. Web services architecture is designed for dynamic program-to-program interaction.

    Microsoft Dynamics NAV 2009 supports Web services, which makes it easy to integrate Microsoft Dynamics NAV with other systems. This is possible with the introduction of Microsoft Dynamics NAV Server.

    There are several types of Web service in Microsoft Dynamics NAV 2009:

    The simplest Web service type is developed by using the page object. By using the page object, Microsoft Dynamics NAV constructs a default Web service that has a fixed set of methods. Generally, it corresponds to general data access, such as get and set individual values or retrieves and updates lists of values.

    Another Web service type involves including codeunits and the functions from those codeunits in the Web service.

    The last type of Web service includes the ability to pass complex data types by using an XMLport object as a parameter in a codeunit function.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-11

    ODBC

    Open DataBase Connectivity, or ODBC, is a standard database access method developed by Microsoft. The goal of ODBC is to make it possible to access any data from any application regardless of which database management system (DBMS) is handling the data. ODBC manages the access of data by inserting a middle layer called a database driver between an application and the DBMS.

    The purpose of the middle layer is to translate the application's data queries into commands that the DBMS understands. For this to work, both the application and the DBMS must be ODBC-compliant; that is, the application must be capable of issuing ODBC commands and the DBMS must be capable of responding to them.

    C/FRONT

    C/FRONT is an application programming interface that can be used to access a Microsoft Dynamics NAV database. C/FRONT facilitates high-level interaction with the Microsoft Dynamics NAV database and enables developers to manipulate any Microsoft Dynamics NAV database.

    The central component of C/FRONT is a library of C functions. These functions provide access to every aspect of data storage and maintenance, and enable the integration of both standard and custom applications with a Microsoft Dynamics NAV database.

    C/FRONT comes as a DLL for direct linkage with a program and also as an OCX that a program can use.

    OCX

    OLE Custom control, or OCX, is an independent program module that can be accessed by other programs in a Microsoft Windows environment. OCX controls end with an .ocx extension. OCX controls represent Microsoft's second generation of control architecture, the first being VBX controls written in Visual Basic.

    Both VBX and OCX controls have now been superseded by Microsoft ActiveX controls. However, ActiveX is backward compatible with OCX controls which means that ActiveX containers such as Microsoft Internet Explorer can execute OCX components.

    There is a vast array of commercially available OCXs that perform a variety of tasks and developers can produce their own. They can use tools such as Microsoft Visual C++ or Visual Basic to create OCXs that can be called by Microsoft Dynamics NAV.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-12

    Automation

    OLE Automation is the name for the ability of one program to expose any or all of its capability for another program to use. The program that provides the functionality being called is the Automation server and the program that uses the functionality of the Automation server is the Automation controller (or client). C/SIDE supports Automation servers by acting as an Automation controller and by using OCXs (custom controls). However, Microsoft Dynamics NAV is not an Automation server. The most common use of Automation within Microsoft Dynamics NAV is to control applications such as Microsoft Word, Microsoft Excel, and Microsoft Outlook.

    Both OCX and Automation are part of Microsoft COM technologies. Developers who plan to use existing COM objects from C/SIDE, such as controls or Automation servers, do not need a complete understanding of COM. Although, understanding how to use objects and how to access the COM object may be necessary. Using the functionality provided by a COM object is no different than using any C/AL function.

    Summary A thorough understanding of C/SIDE enables developers to streamline their development processes by learning how to develop customizations and integrations for the Microsoft Dynamics NAV system. This training material explains how to navigate within the development environment, how to create and use the basic objects, and how to implement best practices for ensuring smooth software upgrades in the future.

    Additional resources (Microsoft Dynamics NAV 2009 Developer and IT Pro Documentation) can be found in the following locations:

    Location Address

    Download Center http://go.microsoft.com/fwlink/?LinkID=126282

    MSDN http://go.microsoft.com/fwlink/?LinkID=126283

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

    DEwertHighlight

  • Chapter 1: Client/Server Integrated Development Environment (C/SIDE)

    1-13

    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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    1-14

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

  • Chapter 2: Tables

    2-1

    CHAPTER 2: TABLES Objectives

    The objectives are:

    Understand the concepts of tables and table components. Examine the concept behind primary and secondary keys, and how to

    set them. Create a simple table with primary and secondary keys and add data

    to the table. Understand the concept of table relation. Set table relations with a filter and condition. Describe the special table fields. Use special table fields to improve table features. Provide an overview of different table types and their characteristics.

    Introduction Tables are the most fundamental objects in Microsoft Dynamics NAV objects. They store records that are collected through forms and pages, for example customers, sales, and inventories. These records are then presented to users through forms, pages and reports.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-2

    Table Fundamentals Records in Microsoft Dynamics NAV databases are stored in tables. A table can be visualized as a two-dimensional matrix, comprising of columns and rows. Each row is a single record, and each column is a field in that record.

    A table consists of table data and the table description. The table data contains the actual records and their fields. The table description specifies the layout and properties of the table and the fields.

    The table description is not directly visible to the user. When a developer creates a table, he/she assigns the table name, ID number and fields. This establishes the table description.

    Field characteristics, such as field name, ID number, data type, and initial value, together with the primary and secondary keys (used to sequence data), are also part of the table description.

    The table description contains properties, triggers, fields, and keys. The following shows components of the table description and how they are related:

    FIGURE 2.1 TABLE COMPONENTS AND THEIR RELATION

    Properties

    The table description contains some properties that are related to the table and properties which are related to the fields or the keys in the table.

    When a table is created, C/SIDE automatically defines several default values for table properties. Depending on the purpose of the table and how it is related to other application objects, these default values may have to be changed.

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

  • Chapter 2: Tables

    2-3

    Some standard table properties such as ID, Name and Caption, differentiate one table from another. Permissions property establishes specific permission for users. Other examples of table properties include LookupFormID and DrillDownFormID which specify which form and page ID are used to look up and drill-down information in the table.

    Table properties can be viewed and modified from the Properties window which is accessed from the Table Designer. The following steps show how to open the Properties window for the Customer table and examine several table properties.

    In Microsoft Dynamics NAV Classic client:

    1. On the Tools menu, click Object Designer. 2. Click the Table button to open the Table list. 3. Select table 18, Customer, and then click the Design button to

    design the Customer table.

    FIGURE 2.2 THE CUSTOMER TABLE IN TABLE DESIGNER

    4. Scroll down and put the cursor on an empty line at the bottom of the

    Table Designer.

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

    DEwertHighlight

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-4

    5. Click View, Properties, or click the Properties button on the Toolbar. The Table - Properties window opens and shows the properties for the table. Here developers can view and modify properties for the Customer table.

    FIGURE 2.3 THE CUSTOMER TABLE AND ITS PROPERTIES

    6. Locate the DataPerCompany property. The value of this property is . The sign shows that Yes is a default value assigned to this property when the table is created and it has not been changed.

    NOTE: To modify the value of a property, select or type a new value in the Value column, and update the property by either pressing ENTER or moving the cursor away from the field.

    7. Locate the LookupFormID property. The value of this property is Customer List. This property specifies that the Customer List form and the Customer List page are used to look up values in the Customer table.

    8. Click the DrillDownFormID property, and press F1. The C/SIDE Reference Guide opens and shows a Help topic for the DrillDownFormID property.

    Triggers

    Triggers are predefined functions that are executed when certain events occur. The bodies of these functions are first empty and must be defined by the developer. Defining C/AL code in triggers lets developers change the default behavior of the system.

    Triggers in a table can be divided into two categories:

    Table triggers Field triggers

    Examples of table triggers include OnInsert which contains statements that are executed when a new record is inserted into the table, and OnModify which contains statements that are executed when a record in the table is modified.

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

  • Chapter 2: Tables

    2-5

    Triggers in a table are edited in the C/AL Editor which is accessed from the Table Designer.

    Fields

    At the very least, a table must have one field. Fields define the actual information kept in a table. Each field has its own properties and triggers.

    Each field has an appropriate data type. Each data type is designed to hold a specific kind of information, such as text, numbers, dates and so on. The following list shows several data types available in the Microsoft Dynamics NAV database system.

    Data Type Description BigInteger This data type is a 64-bit integer. It is used to store large

    whole numbers.

    Binary This data type contains binary data. The binary data is stored in the record. The corresponding SQL data type is VARBINARY. The Binary data type is removed from Microsoft Dynamics NAV 2009.

    BLOB A Binary Large Object (BLOB) is used to store bitmaps and memos. The BLOB is not stored in the record, but in the BLOB area of the table. The corresponding SQL data type is IMAGE.

    Boolean This data type indicates the values TRUE or FALSE. When formatted, a boolean field is displayed as Yes or No. The corresponding SQL data type is TINYINT.

    Code This data type denotes a special type of alphanumeric string which is right-justified if the contents are numbers only. If letters or blanks occur among the numbers, the contents are left-justified. All letters are converted to uppercase upon entry. The field must be defined to be between 1 and 250 characters. In the SQL Server Option for Microsoft Dynamics NAV, code fields work in a different way. The SQL Data Type property can be used to indicate whether code fields can contain integers or text strings. The corresponding SQL data type is VARCHAR.

    Date This data type indicates a date value in the range from January 3, 1 to December 31, 9999. An undefined date is expressed as 0D. All dates have a corresponding closing date. The system considers the closing date for a given date as a period that follows the given date but comes before the next normal date; that is, a closing date is sorted immediately after the corresponding normal date but before the next normal date. The corresponding SQL data type is DATETIME.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-6

    Data Type Description DateFormula This data type is used to contain a date formula that has the

    same capabilities as an ordinary input string for the CALCDATE Function (DATE). The following shows examples of DateFormula: 30D (30 days) CM+1M (current month plus one month) D15 (the 15th of each month)

    DateTime This data type represents a point in time as a combined date and time. The DateTime is stored in the database as Coordinated Universal Time (UTC) and is always displayed as local time in Microsoft Dynamics NAV. Local time is determined by the time zone regional settings that are used by the client computer. DateTimes must always be entered as local time. When a DateTime is entered as local time, it is converted to UTC by using the current settings for the time zone and daylight saving time. The DateTime data type does not support closing dates.

    Decimal This data type denotes a decimal number from -999,999,999,999,999.99 to +999,999,999,999,999.99. In Microsoft Dynamics NAV 2009, the Decimal data type is mapped to the Microsoft .NET Common Language Runtime (CLR) Decimal data type and the precision and limits behave slightly differently than the Binary Coded Decimal (BCD) data type in previous versions of C/AL.

    Duration This data type represents the difference between two points in time, in milliseconds. This value can be negative.

    GUID A Globally unique identifier (GUID) is used for the global identification of objects, programs, records, and so on.

    Integer This data type indicates a whole number between -2,147,483,647 and 2,147,483,647. The corresponding SQL data type is INTEGER.

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

    DEwertHighlight

    DEwertHighlight

  • Chapter 2: Tables

    2-7

    Data Type Description

    Option This data type indicates an option value which is an integer in the range -2,147,483,647 and 2,147,483,647. An option field is defined by using an option string. This is a comma-separated list of strings that represent each valid value of the field. This string is used when a field of type Option is formatted and its value is converted into a string. For example: The Option field Color is defined by using the option string 'Red,Green,Blue'. Valid values of the field are then 0, 1 and 2, with 0 representing Red and so on. When the Color field is formatted, 0 is converted into the string Red, 1 into Green, and 2 into Blue.

    RecordID This data type contains the table number and the primary key of a table.

    TableFilter This data type is used to apply a filter to another table. This can only be used to apply security filters from the Permission table.

    Text This data type denotes an alphanumeric string. The string must be defined to be between 1 and 1024 characters. An empty text string has the length of zero. The corresponding SQL data type is VARCHAR.

    Time This data type indicates any time in the range 00:00:00 to 23:59:59.999. An undefined time is expressed as 0T. The corresponding SQL data type is DATETIME.

    Field Properties

    Some field properties are used to identify the field among other fields, such as ID, Name and Caption. Other field properties are used to establish data type and set the fields behavior, such as DataType, Enabled, and NotBlank property. The following steps show how to open the Properties window for one of the fields (the No. field) in the Customer table.

    1. Design table 18, Customer, from the Object Designer. 2. Click the No. field, and then click View, Properties, or click the

    Properties button on the Toolbar.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-8

    3. The No. Properties window opens and shows the properties for the field. Here developers can view and modify properties for the No. field.

    FIGURE 2.4 THE NO. FIELD PROPERTIES

    4. Locate the NotBlank property.

    The value of this property is . This property prevents leaving this field blank. It is used on most primary key fields.

    Field Triggers

    Each field has the following triggers:

    Fields Trigger Name When it is executed OnValidate Data is entered in a field or when

    .VALIDATE is executed in C/AL code.

    OnLookup Lookup (or F6) is activated.

    Table and field triggers can be viewed and modified from the C/AL Editor which is accessed from the Table Designer. The following steps show how to view and modify the fields and table triggers of the Customer table.

    1. Design table 18, Customer, from the Object Designer.

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

    DEwertHighlight

    DEwertHighlight

    DEwertHighlight

  • Chapter 2: Tables

    2-9

    2. Click View, C/AL Code, or click the C/AL Code button on the Toolbar. The C/AL Editor opens and shows all the triggers available to the Customer table and its fields. From the top, the table triggers are shown, followed by the field triggers and the function triggers at the bottom.

    FIGURE 2.5 THE CUSTOMER TABLE TRIGGERS

    Keys

    The table description contains a list of keys. A key is a sequence of one or more field IDs from the table. Up to 40 keys can be associated to a table. Keys are used to define the sorting method of records in a table, although this is not the only use of keys.

    The following steps show how to view the Customer table keys.

    1. Design table 18, Customer, from the Object Designer. 2. Click View, Keys. The Keys window opens. It shows the keys

    defined for the Customer table.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-10

    The keys associated with a table, also have properties that describe their behavior. The following steps show how to open the Properties window for the Customer table key.

    1. In the Keys window, click any of the keys. 2. Click View, Properties, or click the Properties button on the

    Toolbar.

    FIGURE 2.6 THE CUSTOMER TABLE KEY AND ITS PROPERTIES

    Primary and Secondary Keys There are two kinds of keys, primary key and secondary key.

    Up to 40 keys can be associated to a table and the first on the list is the primary key. All other keys are secondary keys, and are optional.

    Primary Keys

    The database keeps track of each record by using the record's primary key. Consider the primary key of a record as the name of the record. The name of each record in a particular table for a particular company must be unique. This name is how the database management system (DBMS) retrieves and updates records.

    The primary key is composed of up to 20 fields in a record. The combination of values in fields in the primary key makes it possible for the DBMS to perform a unique identification of each record. The primary key determines the logical order in which records are stored, regardless of their physical placement on a disk.

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

  • Chapter 2: Tables

    2-11

    Logically, the records are stored sequentially in ascending order, sorted according to the primary key. Before adding a new record to a table, the DBMS checks that the information in primary key fields in the record is unique and only then inserts the record into its correct logical position. Because the records are sorted as they are entered, the database is always structurally correct. This enables fast data manipulation and retrieval.

    The primary key is always active. The DBMS keeps the table sorted in primary key order and rejects records with duplicate values in primary key fields. Therefore, the values in the primary key must always be unique. It is not the value in each field in the primary key that must be unique, but the combination of values in all the fields consisting of the primary key. The Microsoft Dynamics NAV database system does not support unkeyed tables.

    Secondary Keys

    Secondary keys are used to view records in an order different from the one in which they are sorted according to the primary key fields.

    The number of fields in the primary key together with all the fields in each secondary key must not exceed 20. Each secondary key can contain up to 20 unique fields. However, these 20 unique fields must also include all the fields from the primary key. The primary key fields that are not mentioned specifically in the secondary key are added to the end of the key by the DBMS.

    This means that if the primary key includes four distinct fields, then a secondary key can include these four fields and at most 16 other fields. Correspondingly, if the primary key consists of 20 distinct fields, then any secondary key must consist only of combinations of these fields.

    When a secondary key is defined and selected as active, the system automatically maintains an index reflecting the sorting order defined by the key. Several secondary keys may be active at the same time.

    A secondary key can be changed into an inactive key. This means that the DBMS does not use time during updates to maintain its index. Moreover, an inactive key does not occupy database space. Inactive keys can be reactivated. This process may consume some time, depending on the size of the table because the DBMS has to scan the table to rebuild the index.

    The fields consisting of the secondary keys are not guaranteed to contain unique data. The DBMS does not reject records with duplicate data in secondary key fields. If two or more records contain identical information in the secondary key, the DBMS uses the primary key for the table to solve this conflict.

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

    DEwertHighlight

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-12

    Demonstration: Create a Simple Table The following demonstration shows how to create a simple table, set the primary key, create secondary keys and add data to the table. The purpose of the table is to record information of Vehicles. This includes the model, serial number, transmission type and date of manufacturing.

    Create a New Table

    The following steps show how to create a new table.

    1. In the Object Designer's Table list, click the New button. The Table Designer opens.

    2. Type the following in the Table Designer:

    Field No. Field Name Data Type Length 10 Model Code 20

    20 Serial No. Integer

    30 Description Text 50

    40 Transmission Option

    50 List Price Decimal

    60 Date of Manufacturing Date

    FIGURE 2.7 THE NEW TABLE

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

  • Chapter 2: Tables

    2-13

    3. Open the Properties window for the Transmission field, and set the following property: o OptionString: Automatic,4-Speed,5-Speed

    FIGURE 2.8 THE TRANSMISSION FIELD PROPERTIES

    NOTE: The options set here are displayed in a drop-down list in the table. If a space is added between the options, or any symbols, such as the greater-than and less-than symbols are added in the option string, those symbols are displayed in the drop-down list.

    4. Close the Properties window. 5. Compile and save the table by clicking File, Save As. The Save As

    dialog box opens. 6. Type 90000 in the ID and Vehicle in the Name, ensure that the

    Compiled check box is selected, and then click OK. This compiles and saves the table.

    FIGURE 2.9 THE SAVE AS WINDOW

    7. Close the table by closing the Table Designer.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-14

    Set the Primary Key

    The Microsoft Dynamics NAV database system does not allow for unkeyed tables. When a new table is created and saved without a key, the first field is defaulted as the first key. Therefore, it defaults and becomes the primary key. With this configuration, there cannot be any two records with the same Model. This is not a good choice for the primary key. The following steps show how to set a correct primary key.

    1. Design table 90000, Vehicle, from the Object Designer. 2. Click View, Keys, to open the Keys window.

    Notice that Model is defaulted as the primary key.

    NOTE: With the current configuration, there can be only one unique model of vehicle in the Vehicle table.

    3. Replace the current primary key with the following: o Key: Model,Serial No.

    FIGURE 2.10 THE VEHICLE TABLE WITH THE PRIMARY KEY

    NOTE: Instead of typing the value directly to the Key field, click the Assist-Edit button on the Key field to open the Field List window. Add the fields to be created as a key in the Field List window and then click OK.

    4. Close the Keys window. 5. Compile, save and close the table.

    NOTE: This enables multiple models of the vehicle in the Vehicle table, as long as they have different serial numbers.

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

  • Chapter 2: Tables

    2-15

    Add Data to the Table

    Generally, data is added to a table through forms or pages. The following steps show how to add data manually directly to the table.

    1. In the Object Designer's Table list, select table 90000, Vehicle, and then click the Run button. The Vehicle table opens in a tabular form. This form is auto-created by the Microsoft Dynamics NAV Classic client. Notice that the table is currently empty.

    2. Type the following in the Vehicle table:

    Model Serial No. Description Transmission List Price

    Date of Mfg

    FORD 5000 Red, Mustang

    Automatic 18,000 01/15/10

    FORD 2000 Blue, F150 5-Speed 26,000 01/15/10

    TOYOTA 1000 Gold, Camry Automatic 23,000 02/01/11

    FORD 3000 Black, Explorer

    Automatic 30,000 01/15/10

    TOYOTA 3000 Black, Tacoma

    5-Speed 20,000 12/15/09

    TOYOTA 2000 Gray, Camry Automatic 22,000 01/15/10

    NOTE: Every new record is sorted in the order of the primary key fields: alphabetically by Model, and then numerically by Serial No.

    FIGURE 2.11 THE VEHICLE TABLE WITH DATA

    3. Close the table.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-16

    Create a Secondary Key

    For some users, the date of manufacturing and the transmission are more important than the model and serial number. Those users may want to change the order of the records on the form to be sorted by Date of Manufacturing and Transmission. To do this, a secondary key must be created. The following steps show how to create a secondary key.

    1. Design table 90000, Vehicle, from the Object Designer. 2. Click View, Keys. The Vehicle - Keys window opens. 3. Click the Assist-Edit button on the Key field of the first blank line

    (second line.) The Field List window opens. 4. Type the following in the Field List window:

    Field Date of Manufacturing

    Transmission

    NOTE: Instead of typing the field name in the Field List window, use the Lookup button to select the fields from the Vehicle table. The order of these fields is important. In the order described, the records are sorted by date of manufacturing first, and then by transmission, if the dates are the same.

    5. Click OK to close the Field List window. The secondary key of Date of Manufacturing,Transmission is created in the Vehicle - Keys window.

    FIGURE 2.12 THE VEHICLE TABLE WITH A SECONDARY KEY

    6. Close the Vehicle - Keys window. 7. Compile, save and close the table.

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

  • Chapter 2: Tables

    2-17

    Use the Secondary Key

    The following steps show how to use the secondary key.

    1. Run table 90000, Vehicle, from the Object Designer. The Vehicle table opens. It contains the data previously entered. The records are sorted in the primary key order.

    2. Click the Sort button on the Toolbar. The Sort window opens. 3. Select the Date of Manufacturing,Transmission key, and then click

    OK. The records immediately re-sort themselves by their Date of Manufacturing and Transmission.

    FIGURE 2.13 THE VEHICLE TABLE SORTED BY THE SECONDARY KEY

    Table Relationships There are three kinds of relationships between tables in relational database design:

    One-to-Many Relationships Many-to-Many Relationships One-to-One Relationships

    The one-to-many relationship is the most common. If a database contains tables with related data, developers can define a relationship between them. Developers relate tables by specifying one or more fields that contain the same value in related records. These matching fields frequently have the same name in each table. The fields can use relationships to do the following:

    Validate data entries. Perform Lookup in other tables. Automatically propagate changes from one table to other tables.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-18

    Table Relation Property

    Table relations are defined by using the TableRelation property. This property lets developers define both simple and advanced table relations. A simple table relation consists of only a table ID and an optional field ID, whereas advanced table relations are typically prefixed with a conditional statement and include filters.

    When developers create a table relation, they specify which field to look up in another table. If the optional field ID is left blank, the first field in the primary key is set to relate to. To make a relation to the second or third field in a primary key, the field ID must be specified.

    NOTE: The field ID specified in the TableRelation property must be in the primary key of the table specified by the table ID in the property. If the field specified is not the first field in the primary key, the other fields that are listed before it in the key must be filtered to one value. This is not a true requirement of the system, but makes sense in a real application to avoid user confusion.

    An example of a table relation is shown in the Sales Header table. The Sales Header table has a Salesperson Code field that relates to the Salesperson/Purchaser table. When the users look up the Salesperson Code field, the Lookup form of the Salesperson/Purchaser table opens.

    FIGURE 2.14 TABLE RELATION IN SALES ORDER'S SALESPERSON CODE

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

    DEwertHighlight

    DEwertHighlight

  • Chapter 2: Tables

    2-19

    Filter Table Relation

    Advanced table relations may involve filtering within the table relation. An example of filtering in a table relation is shown in the Sales Line table. The Sales Line table has a Location Code field that relates to the Location table.

    FIGURE 2.15 FILTERED TABLE RELATION IN SALES ORDER LINE'S LOCATION CODE

    The Location table holds all the records for location. This includes those used as In-Transit locations. When users select a location in the Sales Line, for example in the Sales Order, they must not be able to select a location that is used as In-Transit locations. Therefore, the table relation must be filtered to show only those locations that are not used as In-Transit locations.

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-20

    Conditional Table Relation

    Advanced table relations may also involve a conditional statement within the table relation. An example of a conditional table relation is also shown in the Sales Line table. The table Sales Line has a No. field that relates to six different tables, depending on the condition of the Type field in the Sales Line.

    FIGURE 2.16 CONDITIONAL TABLE RELATION IN SALES ORDER LINE'S NO.

    If the users select Item as the Type in the Sales Line, for example in the Sales Order, then the No. field relates to the Item table. When the users look up the No. field, the Lookup form of the Item table opens. Whereas if the users select Resource as the Type, the No. field relates to the Resource table, and when the users look up the No. field, the Lookup form of the Resource table opens.

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

  • Chapter 2: Tables

    2-21

    Demonstration: Table Relations The following demonstration shows how to create a table to record sales transactions and create fields that have a table relation to other tables.

    Create a Table with Table Relations

    The following steps show how to create a table with table relations.

    1. In the Object Designer's Table list, click the New button. The Table Designer opens.

    2. Type the following in the Table Designer:

    Field No. Field Name Data Type

    Length

    10 Line No. Integer

    20 Salesperson Code Code 10

    30 Type Option

    40 No. Code 20

    50 Amount Decimal

    Now, the table looks as follows:

    FIGURE 2.17 THE TABLE DESIGNER

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

  • C/SIDE Introduction in Microsoft Dynamics NAV 2009

    2-22

    3. Open the Properties window for the Type field, and set the following property: o OptionString: G/L Account,Item,Resource

    FIGURE 2.18 THE TYPE - PROPERTIES WINDOW

    4. Close the Properties window. 5. Compile and save the table with the ID 90001 and the name Sales

    Transactions.

    Set a Table Relation with a Filter

    The Sales Transactions table must record the salesperson of a particular transaction. The Salesperson