Book Image

Programming Microsoft Dynamics NAV 2013 - Third Edition

Book Image

Programming Microsoft Dynamics NAV 2013 - Third Edition

Overview of this book

Microsoft Dynamics NAV 2013 is a complete and robust ERP system that is accompanied by a comprehensive set of development tools. You will learn how to master these tools and tailor Microsoft Dynamics NAV 2013 to meet your customer's specific business needs."Programming Microsoft Dynamics® NAV 2013" will lead you from start to finish, teaching you how to use this incredible ERP software whilst simultaneously making you a more productive developer. You'll learn how to implement your solutions, as well as evaluating, managing and appraising Dynamics NAV 2013 productions and projects.You will be empowered with the skills and knowledge that you need to get the job done and exceed your client's expectations. Step by step, you will learn how to use NAV, master the C/AL programming language, as well as the construction and uses of each object type. Ultimately, you will be able to bring your NAV 2013 solution together with fantastic efficiency.Hands-on development examples and additional material teach you by example and uncover the insider knowledge that only years of experience can provide, truly unleashing your productivity and potential.
Table of Contents (19 chapters)
Programming Microsoft Dynamics NAV 2013
Credits
Foreword
About the Authors
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Congratulations on beginning your study of Microsoft Dynamics NAV, C/SIDE and C/AL. You are joining a high-quality, worldwide group of experienced developers. This is a collegial community of C/AL developers who readily and generously share their knowledge. There are formal and informal organizations of NAV-focused users, developers, and vendor firms on the Web and scattered around the globe. NAV is one of the best customizable ERP systems on the market. It continues to grow and prosper.

The information in this book will help you to shorten your learning curve on how to program for the NAV 2009 ERP system using the C/AL language, the C/SIDE integrated development environment and their capabilities. Welcome aboard and enjoy the journey.

A Business history timeline

The current version of Microsoft Dynamics NAV is the result of inspiration and hard work along with some good fortune and excellent management decision making over almost the last thirty years.

The beginning

Three college friends, Jesper Balser, Torben Wind, and Peter Bang, from Denmark Technical University (DTU) founded their computer software business in 1984 when they were in their early twenties. That business was Personal Computing & Consulting (PC & C) and its first product was called PC Plus.

Single user PC Plus

PC Plus was released in 1985 with a primary goal of ease of use. An early employee said its functional design was inspired by the combination of a manual ledger journal, an Epson FX 80 printer, and a Canon calculator. Incidentally, Peter Bang is the grandson of one of the founders of Bang & Olufsen, the manufacturer of home entertainment systems par excellence.

PC Plus was PC DOS-based, a single-user system. PC Plus' design features included:

  • An interface resembling the use of documents and calculators

  • Online help

  • Good exception handling

  • Minimal computer resources required

The PC Plus product was marketed through dealers in Denmark and Norway.

Multiuser Navigator

In 1987, PC & C released a new product, the multiuser Navigator and a new corporate name, Navision. Navigator was quite a technological leap forward. It included:

  • Client/Server technology

  • Relational database

  • Transaction-based processing

  • Version management

  • High-speed OLAP capabilities (SIFT technology)

  • A screen painter tool

  • A programmable report writer

In 1990, Navision was expanding its marketing and dealer recruitment efforts into Germany, Spain, and the United Kingdom. Also in 1990, V3 of Navigator was released. Navigator V3 was still a character-based system, albeit a very sophisticated one. If you had an opportunity to study Navigator V3.x, you would instantly recognize the roots of today's NAV product. By V3, the product included:

  • A design based on object-oriented concepts

  • Integrated 4GL Table, Form, and Report Design tools (the IDE)

  • Structured exception handling

  • Built-in resource management

  • The original programming language that became C/AL

  • Function libraries

  • The concept of regional or country-based localization

When Navigator V3.5 was released, it also included support for multiple platforms and multiple databases. Navigator V3.5 would run on both Unix and Windows NT networks. It supported Oracle and Informix databases as well as the one developed in-house.

At about this time, several major strategic efforts were initiated. On the technical side, the decision was made to develop a GUI-based product. The first prototype of Navision Financials (for Windows) was shown in 1992. At about the same time, a relationship was established that would take Navision into distribution in the United States. The initial release in the US in 1995 was V3.5 of the character-based product, rechristened Avista for US distribution.

Navision financials for Windows

In 1995, Navision Financials V1.0 for Microsoft Windows was released. This product had many (but not all) of the features of Navigator V3.5. It was designed for complete look-and-feel compatibility with Windows 95. There was an effort to provide the ease of use and flexibility of development of Microsoft Access. The new Navision Financials was very compatible with Microsoft Office and was thus sold as "being familiar to any Office user". Like any V1.0 product, it was fairly quickly followed by a V1.1 that worked much better.

In the next few years, Navision continued to be improved and enhanced. Major new functionalities were added:

  • Contact Relation Management (CRM)

  • Manufacturing (ERP)

  • Advanced Distribution (including Warehouse Management)

Various Microsoft certifications were obtained, providing muscle to the marketing efforts. Geographic and dealer base expansion continued apace. By 2000, according to the Navision Annual Report of that year, the product was represented by nearly 1,000 dealers (Navision Solution Centers) in 24 countries and used by 41,000 customers located in 108 countries.

Growth and mergers

In 2000, Navision Software A/S and its primary Danish competitor, Damgaard A/S, merged. Product development and new releases continued for the primary products of both original firms (Navision and Axapta). In 2002, the now much larger Navision Software, with all its products (Navision, Axapta, and the smaller, older C5 and XAL) was purchased by Microsoft, becoming part of the Microsoft Business Systems division along with the previously purchased Great Plains Software business and its several product lines. The Navision and Great Plains products all received a common rebranding. Navision was renamed to Dynamics NAV.

Continuous enhancement

As early as 2003, research began with the Dynamics NAV development team planning moves to further enhance NAV, taking advantage of various parts of the Microsoft product line. Goals were defined to increase integration with products such as Microsoft Office and Microsoft Outlook. Goals were also set to leverage the functional capabilities of Visual Studio and SQL Server, among others. All the while, there was a determination not to lose the strength and flexibility of the base product.

This was to be a massive change that would require an almost complete rewrite of the underlying code, the foundation that's normally not visible to the outside world. To accomplish that while not destroying the basic user interface, the business application model or the development environment, turned out to be a larger, more complex effort than hoped for. The first public views of this new version of the system, a year or two later, were not greeted with universal enthusiasm from the NAV technical community. But the Dynamics NAV development team persevered and Microsoft continued supporting the investment, until NAV 2009 was released in late 2008 followed by NAV 2013 in late 2012. The biggest hurdles to the new technologies had been cleared.

A new user interface, the Role Tailored Client, was created as part of this renewal. NAV is now based on Microsoft's SQL Server and is well integrated with other Microsoft products such as Office, Outlook and SharePoint. The new product versions take increasing advantage of SQL Server technologies. Development is more integrated with Visual Studio and more .NET compliant. The product is becoming more open and, at the same time, more sophisticated, supporting features such as Web Services access, integration of third-party controls, and RDLC reporting. In our industry, it would be appropriate to say "To survive is to change." Change and survival are part of what Dynamics NAV does very well.

Microsoft continues to invest in, enhance, and advance NAV. More new capabilities and features are yet to come, continuing to build on the successes of the past. We all benefit.

C/AL's roots

One of the first questions asked by people new to C/AL is often "what other programming language is it like?" The best response is "Pascal". If the questioner is not familiar with Pascal, the next best response would be "C" or "C#".

At the time the three founders of Navision were attending classes at Denmark Technical University (DTU), Pascal was in wide use as a preferred language not only in computer courses, but in other courses where computers were tools and software had to be written for data analyses. Some of the strengths of Pascal as a tool in an educational environment also served to make it a good model for Navision's business applications development.

Perhaps coincidentally (perhaps not) at DTU in this same time period, a Pascal compiler called Blue Label Pascal was developed by Anders Hejlsberg. That compiler became the basis for what was Borland's Turbo Pascal, which was the "everyman's compiler" of the 1980s because of its low price. Anders went with his Pascal compiler to Borland. While he was there Turbo Pascal morphed into the Delphi language and IDE tool set under his guidance.

Anders later left Borland and joined Microsoft, where he led the C# design team. Much of the NAV-related development at Microsoft is now being done in C#. So the Pascal-C/AL-DTU connection has come full circle, only now it appears to be C#-C/AL. Keeping it in the family, Anders' brother, Thomas Hejlsberg also works at Microsoft on NAV. Each in their own way, Anders and Thomas continue to make significant contributions to Dynamics NAV.

In a discussion about C/AL and C/SIDE, Michael Nielsen of Navision and Microsoft, who developed the original C/AL compiler, runtime, and IDE, said that the design criteria were to provide an environment that could be used without:

  • Dealing with memory and other resource handling

  • Thinking about exception handling and state

  • Thinking about database transactions and rollbacks

  • Knowing about set operations (SQL)

  • Knowing about OLAP (SIFT)

Paraphrasing some of Michael's additional comments, the goals of the language and IDE design were to:

  • Allow the developer to focus on design, not coding, but still allow flexibility

  • Provide a syntax based on Pascal stripped of complexities, especially relating to memory management

  • Provide a limited set of predefined object types, reducing the complexity and learning curve

  • Implement database versioning for a consistent and reliable view of the database

  • Make the developer and end user more at home by borrowing a large number of concepts from Office, Windows, Access, and other Microsoft products

Michael is still working as part of the Microsoft team in Denmark on new capabilities for NAV. Another example of how, once part of the NAV community, most of us want to stay part of that community.

What you should know

This book will not teach you programming from scratch, nor will it tutor you in business principles. To get the maximum out of this book, you should come prepared with some significant experience and knowledge including the following attributes:

  • Experienced developer

  • More than one programming language

  • IDE experience

  • Knowledgeable about business applications

  • Good at self-directed study

If you have those attributes, then by careful reading and performance of the suggested exercises in this book, it will help you become productive with C/AL and NAV much more rapidly. In addition, your knowledge will be broader and deeper than it would be otherwise.

For executives, consultants, managers and others who aren't developers, but want to learn about the development technology and capabilities of Dynamics NAV, this book is still an excellent resource. If you fit in one of those or similar categories, start by studying Chapter 1, An Introduction to NAV 2013, in detail for a good overview of what NAV is and its tools. Then review sections of other chapters as the topics apply to your areas of interest.

This book's illustrations are from the W1 Cronus database V2013.

Hopefully this book will smooth your path to knowledge of Dynamics NAV 2013 and shine a little light on challenges and opportunities alike. Your job is to take advantage of this opportunity to learn, to expand your knowledge of NAV, and then use your new skills productively.

What this book covers

Chapter 1, An Introduction to NAV 2013, starts with an overview of NAV as a business application system. This is followed by an introduction to the seven types of NAV objects, and the basics of C/AL and C/SIDE. Then we will do some hands-on work, defining Tables, multiple Page types, and a Report. We'll close with a brief discussion of how backups and documentation are handled in C/SIDE.

Chapter 2, Tables, focuses on the foundation level of NAV data structure—Tables and their structures. We will cover Properties, Triggers (where C/AL resides), Field Groups, Table Relations and SumIndexFields. We'll work our way through hands-on creation of several tables in support of our example application. We will also review the types of tables found in the NAV applications.

Chapter 3, Data Types and Fields, will help you learn about fields, the basic building blocks of NAV data structure. We will review the different data types in NAV. We will cover all the field properties and triggers in detail. We'll also review the three different Field classes. We'll conclude with a discussion of the concept of filtering and how it should be considered in database structure design.

Chapter 4, Pages – the User's Interactive Interface, covers the different types of pages, their structures (Triggers, Properties) and general usage. We'll build several pages for our example application using the Page Wizard and Page Designer. We will also study the different types of controls that can be used in pages. In addition we'll review how and where actions are added to pages.

Chapter 5, Queries and Reports, will help you learn about both Queries and Reports, two methods of extracting data for presentation to users. For Queries, we will study how they are constructed and some of the ways they are utilized. For Reports, we will walk through report data flow and the variety of different report types. We will study the two Report Designers, the C/SIDE Report Designer and the Visual Studio Report Designer and how a NAV report is constructed using both of these. We'll learn what aspects of reports use one designer and what aspect use the other. As in previous studied objects, we will discuss Properties and Triggers. We will review how reports can be made interactive and will do some hands-on report creation.

Chapter 6, Introduction to C/SIDE and C/AL, will help you learn about general Object Designer Navigation as well as the individual Designers (Table, Page, Report). We'll study C/AL code construction, syntax, variable types, expressions, operators and functions. We will then take a closer look at some of the more frequently used built-in functions. This chapter will wrap up with an exercise adding some C/AL code to report objects created in an earlier exercise.

Chapter 7, Intermediate C/AL, explores the C/AL development tools and techniques. We will review some more advanced built-in functions including those relating to dates and decimal calculations, both critical business application tools. We'll study C/AL functions that support process flow control functions, input/output, and filtering. Then we'll do a review of methods of communication between objects. Finally, we'll apply some of what we've learned to enhancing our example application.

Chapter 8, Advanced NAV Development Tools, we will review some of the more important elements of the Role Tailored User Experience, in particular the Role Center Page construction. We will dig into the components of a Role Center Page and how to build one. We'll also cover two of the powerful ways of connecting NAV applications to the world outside of NAV, XMLports and Web Services. To better understand these, we will not only review their individual component parts, but will go through the hands-on effort of building an example of each one.

Chapter 9, Develop, Debug, Deliver, covers in detail how NAV functions are constructed and learn how to construct our own functions. We learn more about tools and features built into C/AL and C/SIDE. We will study the new debugger, review the support for Test-driven Development, and take a look at the ability to integrate .NET Client Add-ins. We will integrate a .NET Add-in into our example applications. Finally, we will review tips for design efficiency, updating and upgrading the system, all with the goal of helping us to become more productive, high quality NAV developers.

Appendix A, Answers to Review Questions, contains answers for all the review questions that appear at the end of each chapter.

Appendix B, Review Questions with Answers, contains all the review questions along with the answers. This is not present in the book but is available as a free download from the following link: http://www.packtpub.com/sites/default/files/downloads/6488EN_App_Final.pdf.

What you need for this book

You will need some basic tools including at least the following:

  • A license and database that you can use for development experimentation. An ideal license is a full Developer's license. If the license only contains the Page, Report, and Table Designer capabilities, you will still be able to do many of the exercises, but you will not have access to the inner workings of Pages and Tables and the C/AL code contained therein.

  • A copy of the NAV Cronus demo/test database for your development testing and study. It would be ideal if you also had a copy of a production database at hand for examination as well. This book's illustrations are from the W1 Cronus database for V2013.

Access to other NAV manuals, training materials, websites and experienced associates will obviously be of benefit, but they are not required for the time with this book to be a good investment.

Who this book is for

This book is for:

  • The business applications software designer/developer who:

    • Wants to become productive in NAV C/SIDE—C/AL development as quickly as possible

    • Understands business applications and the type of software required to support those applications

    • Has significant programming experience

    • Has access to a copy of NAV 2013 including at least the Designer granules and a standard Cronus demo database

    • Is willing to do the exercises to get hands-on experience

  • The Reseller manager or executive who wants a concise, in depth view of NAV's development environment and tool set

  • The technically knowledgeable manager or executive of a firm using NAV that is about to embark on a significant NAV enhancement project

  • The technically knowledgeable manager or executive of a firm considering purchase of NAV as a highly customizable business applications platform

  • The experienced business analyst or consultant or advanced student of applications software development who wants to learn more about one of the most widely used, most flexible business application systems available

The reader of this book:

  • Does not need to be expert in object-oriented programming

  • Does not need previous experience with NAV, C/AL, or C/SIDE

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "One is known as comma-separated value or comma-delimited files (usually having a .csv file extension)."

A block of code is set as follows:

IF Type = 'Resource' THEN No. := Resource.No.
    ELSE IF Type = 'Show' THEN No. := Radio Show.No.
    ELSE IF Type = 'Item' THEN No. := Item.No.

Any command-line input or output is written as follows:

"C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe" -configure -profile:"WDTU Test"

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "We can set the Work Date by selecting the Microsoft Dynamics icon dropdown and navigating to the Set Work Date… option."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.