Packt Publishing
Table of Contents
NAV 2015 – an ERP system 2
Financial Management 4
Manufacturing 4
Supply Chain Management 5
Business Intelligence and reporting 6
Relationship Management 7
Human Resource management 8
Project Management 8
Significant changes in NAV 2015 8
Application changes 9
Client enhancements 9
Development tools 9
Other areas 10
A developer's overview of NAV 2015 10
NAV object types 11
The C/SIDE integrated development environment 11
Object Designer tool icons 12
The C/AL programming language 13
NAV object and system elements 14
NAV functional terminology 18
User interface 19
Hands-on development in NAV 2015 21
The NAV 2015 development exercise scenario 21
Getting started with application design 22
Application tables 22
Designing a simple table 23
Creating a simple table 24
Pages 27
Standard elements of pages 27
List pages 28
Card pages 28
Document pages 29
Journal/Worksheet pages 31
Creating a List page 31
Creating a Card page 35
Creating some sample data 40
Creating a List Report 41
Other NAV object types 49
Codeunits 49
Queries 50
MenuSuites 50
XMLports 50
Development backups and documentation 51
Summary 52
Review questions 52
An overview of tables 58
Components of a table 59
Naming a table 60
Table numbering 61
Table properties 61
Table triggers 64
Keys 67
SumIndexFields 70
Field Groups 71
Enhancing our sample application 75
Creating and modifying tables 75
Assigning a Table Relation property 80
Assigning an InitValue property 83
Adding a few activity-tracking tables 84
New tables for our WDTU project 85
New list pages for our WDTU project 88
Keys, SumIndexFields, and table relations in our examples 88
Secondary keys and SumIndexFields 88
Table relations 90
Modifying a standard table 92
Version list documentation 93
Types of tables 95
Fully Modifiable tables 95
Master 96
Journal 97
Template 98
Ledger 99
Reference tables 101
Register 103
Posted Document 104
Setup 106
Temporary 107
Content modifiable tables 108
System 108
Read-only tables 109
Virtual 110
Summary 111
Review questions 112
Basic definitions 116
Fields 116
Field properties 117
Field triggers 124
Data structure examples 125
Field numbering 125
Field and Variable naming 126
Data types 127
Fundamental data types 127
Numeric data 128
String data 129
Date/Time data 130
Complex data types 131
Data structure 132
Objects 132
Automation 132
Input/Output 133
DateFormula 133
References and other data types 140
Data type usage 141
FieldClass property options 142
FieldClass – Normal 143
FieldClass – FlowField 143
FieldClass – FlowFilter 146
FlowFields and a FlowFilter for our application 149
Filtering 154
Experimenting with filters 155
Accessing filter controls 162
Development Environment filter access 162
Role Tailored Client filter access 163
Summary 165
Review questions 165
Page design and structure overview 170
Page design guidelines 171
The NAV 2015 page structure 172
Types of pages 175
Role Center page 175
List page 177
Card page 178
Document page 178
FastTab 179
ListPlus page 180
Worksheet (Journal) page 181
ConfirmationDialog page 181
StandardDialog page 182
NavigatePage 182
Navigate page 344 183
Special pages 183
Request page 184
Departments page 184
Page parts 185
FactBox Area 186
Charts 187
Chart part 187
Page names 188
Page Designer 189
New Page Wizard 190
Page components 194
Page Triggers 195
Page properties 196
Page Preview tool 199
Inheritance 201
WDTU Page Enhancement – part 1 202
Page controls 206
Control types 209
Container controls 209
Group controls 209
Field controls 213
Page Part controls 216
Page control triggers 218
Bound and Unbound Pages 219
WDTU Page Enhancement – part 2 219
Page Actions 222
Page Action Types and Subtypes 224
Action Groups 225
Action properties 225
Navigation Pane Button actions 228
Actions Summary 229
Learning more 230
UX (User Experience) Guidelines 230
Creative plagiarism and patterns 230
Experimenting on our own 231
Experimentation 231
Summary 234
Review questions 234
Queries 238
Building a simple Query object 239
Query and Query component properties 244
Query properties 244
The DataItem properties 245
Column properties 246
Reports 247
What is a report? 248
Four NAV report designers 249
NAV report types 252
Report types summarized 256
Report naming 256
Report components – overview 257
Report structure 257
Report data overview 258
Report Layout overview 259
Report data flow 260
Report components – detail 263
C/SIDE Report properties 263
SQL Server Report Builder – Report properties 265
Report triggers 267
Request Page Properties 268
Request page triggers 268
DataItem properties 269
DataItem triggers 271
Creating a Report in NAV 2015 272
Learn by experimentation 272
Report building – phase 1 273
Report building – phase 2 276
Report building – phase 3 280
Modifying an existing report with Report Designer or Word 285
Runtime rendering 290
Inheritance 290
Interactive report capabilities 290
Interactive sorting 291
Interactive visible/not visible 292
Request page 293
Add a Request Page option 294
Processing-Only reports 297
Creative report plagiarism and patterns 297
Summary 298
Review questions 298
Understanding C/SIDE 302
Object Designer 302
Starting a new object 304
Query Designer 306
XMLport Designer 307
MenuSuite Designer 308
Object Designer Navigation 311
Importing objects 314
Text objects 318
Some useful practices 318
Some C/AL naming conventions 320
Variables 322
C/SIDE programming 327
Non-modifiable functions 328
Modifiable functions 328
Custom functions 330
C/AL syntax 337
Assignment and punctuation 337
Expressions 338
Operators 339
Frequently used C/AL functions 344
The MESSAGE function 344
The ERROR function 345
The CONFIRM function 347
The STRMENU function 348
Record functions 349
FIND functions 352
Conditional statements 356
The BEGIN–END compound statement 356
The IF–THEN–ELSE statement 356
Indenting code 357
Some simple coding modifications 358
Adding field validation to a table 358
Adding code to a report 363
Lay out the new Report Heading 364
Save and test 365
Lookup Related table data 365
Layout the new report body 366
Save and test 368
Handling User-entered report options 368
Defining the Request Page 370
Finishing the processing code 371
Test the completed report 372
Output to Excel 372
Summary 373
Review questions 374
C/AL Symbol Menu 378
Internal documentation 380
Validation functions 384
TESTFIELD 384
FIELDERROR 385
INIT 386
VALIDATE 387
Date and Time functions 387
TODAY, TIME, and CURRENTDATETIME functions 388
WORKDATE function 388
DATE2DMY function 389
DATE2DWY function 390
DMY2DATE and DWY2DATE functions 390
CALCDATE function 391
Data conversion and formatting functions 392
ROUND 392
FORMAT function 393
EVALUATE function 394
FlowField and SumIndexField functions 395
CALCFIELDS function 396
SETAUTOCALCFIELDS function 397
CALCSUMS function 398
CALCFIELDS and CALCSUMS comparison 398
Flow control 399
REPEAT-UNTIL 399
WHILE-DO 400
FOR-TO or FOR-DOWNTO 400
CASE-ELSE statement 401
WITH-DO statement 403
QUIT, BREAK, EXIT, and SKIP functions 404
QUIT function 404
BREAK function 404
EXIT function 405
SKIP function 405
Input and Output functions 405
NEXT function with FIND or FINDSET 406
INSERT function 406
MODIFY function 407
Rec and xRec 408
DELETE function 408
MODIFYALL function 408
DELETEALL function 409
Filtering 409
SETFILTER function 410
COPYFILTER and COPYFILTERS functions 411
GETFILTER and GETFILTERS functions 411
FILTERGROUP function 412
MARK function 413
CLEARMARKS function 413
MARKEDONLY function 413
RESET function 414
InterObject communication 414
Communication via data 414
Communication through function parameters 414
Communication via object calls 415
Enhancing the WDTU application 416
Modifying Table Fields 417
Add Validation logic 420
Creating the Playlist Subform page 423
Creating a function for our Factbox 431
Creating a Factbox page 435
Summary 439
Review questions 440
NAV process flow 444
Initial setup and data preparation 446
Transaction entry 446
Testing and posting the Journal batch 447
Utilizing and maintaining the data 447
Data maintenance 448
Role Center pages 448
The Role Center structure 449
The Role Center activities page 453
Cue Groups and Cues 454
Cue source table 455
Cue Group Actions 458
System Part 459
Page Parts 460
Page Parts not visible 460
Page Part Charts 461
Page Parts for user data 463
The Navigation Pane and Action menus 463
Action Designer 465
Create a WDTU Role Center Ribbon 468
The Navigation Pane 476
XMLports 479
XMLport components 480
XMLport properties 481
XMLport triggers 485
XMLport data lines 485
XMLport line properties 486
The Element or Attribute 490
XMLport line triggers 491
XMLport Request Page 493
Web services 493
Exposing a web service 495
Publishing a web service 496
Enabling web services 497
Determining what was published 497
XMLport – a web services integration example for WDTU 500
Summary 507
Review questions 507
Creating new C/AL routines 512
Callable functions 513
Codeunit 358 – Date FilterCalc 513
Codeunit 359 – Period Form Management 515
Codeunit 365 – Format Address 516
Codeunit 396 – NoSeriesManagement 518
Function models to review and use 519
Management codeunits 520
Multi-language system 521
Multi-currency system 522
Navigate 523
Debugging in NAV 2015 526
Text Exports of Objects 527
Dialog function debugging techniques 529
Debugging with MESSAGE and CONFIRM 529
Debugging with DIALOG 530
Debugging with text output 530
Debugging with ERROR 531
The NAV 2015 Debugger 531
Activating the Debugger 533
Attaching the Debugger to a Session 534
Creating Break Events 535
The Debugger window 537
Changing code while debugging 539
C/SIDE Test-driven development 539
Other Interfaces 542
Automation Controller 543
Linked Data Sources 544
NAV Application Server (NAS) 544
Client Add-ins 544
Client Add-in construction 545
WDTU Client Add-in 546
Client Add-in comments 561
Customizing Help 562
NAV development projects – general guidance 563
Knowledge is the key 563
Data-focused design 563
Defining the needed data views 564
Designing the data tables 564
Designing the user data access interface 565
Designing the data validation 565
Data design review and revision 565
Designing the posting processes 566
Designing the supporting processes 566
Double-check everything 566
Design for efficiency 567
Disk I/O 567
Locking 568
Updating and upgrading 569
Design for updating 569
Customization project recommendations 570
Testing 571
Deliverables 575
Finishing the project 576
Plan for upgrading 576
Benefits of upgrading 577
Coding considerations 577
Good documentation 578
Low-impact coding 578
Supporting material 579
Summary 580
Review questions 580
Appendix: Review Answers 583
Index 593
Preface
Welcome to the worldwide community of Microsoft Dynamics NAV developers. This is a collegial environment populated by C/AL developers who readily and generously share their knowledge. There are formal and informal organizations of NAV-focused users, developers, and vendor firms scattered around the globe and active on the Web. Our community continues to grow and prosper, now including over 110,000 user companies worldwide.
The information in this book will help you to shorten your learning curve of how to program for the NAV 2015 ERP system using the C/AL language, the C/SIDE integrated development environment and their capabilities. We hope you enjoy working with NAV as much as we have.
A brief history of NAV
Each new version of Microsoft Dynamics NAV is the result of inspiration and hard work along with some good fortune and expert technical investment over the last thirty years.
Single user PC Plus
PC Plus was released in 1985 with the 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 a PC DOS-based single user system. PC Plus' design features included these:
• 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.
The multi-user Navigator
In 1987, PC & C released a new product, the multi-user Navigator and a new corporate name, Navision. Navigator was quite a technological leap forward.
It included the following:
• Client/Server technology
• A 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 in 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 get an opportunity to study Navigator V3.x, you would instantly recognize the roots of today's NAV product. By V3, the product included these features:
• 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 databases. Navigator V3.5 would run on both Unix and Windows NT networks.
It supported the Oracle and Informix databases, as well as the one developed in-house.
Around 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 as Avista for the 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 quickly followed by a much improved V1.1.
In the next few years, Navision continued to be improved and enhanced. Major new functionalities were added, such as:
• 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. All the Navision and Great Plains products received a common
rebranding as the Dynamics product line. Navision was renamed Dynamics NAV.
Continuous enhancement
As early as 2003, research began with the Dynamics NAV development team planning moves to further enhance NAV and take 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.
NAV 2009 was released in late 2008, NAV 2013 in late 2012, followed by NAV 2015 in late 2014. The biggest hurdles to the new technologies have been cleared. A new user interface, the Role Tailored Client, was created as part of this renewal. NAV was tightly integrated with Microsoft's SQL Server and other Microsoft products such as Office, Outlook, and SharePoint. 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, Web and tablet clients, the integration of third-party controls, RDLC, and Word-based reporting, and so on.
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 will all benefit.
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 also 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 the 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 as a Software Architect. 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 the following:
• 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 do the following:
• 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, reduce 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. This is another example of how, once part of the NAV community, most of us want to stay part of this community.
What you should know
To get the maximum out of this book as a developer, you should have the following attributes:
• Be an experienced developer
• Know more than one programming language
• Have IDE experience
• Be knowledgeable about business applications
• Be good at self-directed study
If you have these attributes, this book will help you become productive with C/AL and NAV much more rapidly.
Even though this book is targeted first at developers, it is also designed to be useful to executives, consultants, managers, business owners, and others who want to learn about the development technology and operational capabilities of Dynamics NAV. If you fit into one of these or similar categories, start by studying Chapter 1, An Introduction to NAV 2015, for a good overview of NAV and its tools. Then you should review sections of other chapters as the topics apply to your specific areas of interest.
This book's illustrations are from the W1 Cronus database Dynamics NAV V2015.
What this book covers
Chapter 1, An Introduction to NAV 2015, 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 and define 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 the 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, we will learn about fields, the basic building blocks of the NAV data structure. We 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 about the concept of filtering and how it should be considered in the database structure design.
Chapter 4, Pages – The Interactive Interface, we will review the different types of pages, their structures (Triggers, Properties) and general usage. We'll build several pages for our example application using Page Wizard and Page Designer. We will also study the different types of controls that can be used in the pages. In addition, we'll
review how and where actions are added to the pages.
Chapter 5, Queries and Reports, we will 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 aspects use the other. As in the 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, we will 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. The chapter will wrap up with an exercise on adding some C/AL code to a report objects created in an earlier exercise.
Chapter 7, Intermediate C/AL, we will dig deeper into 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 the 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 enhance 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 XMLports and Web Services, two of the powerful ways of connecting NAV applications to the world outside of NAV. To better understand these, we will not only review their individual component parts, but also go through the hands-on effort of building an example of each one.
Chapter 9, Successful Conclusions, we will study in detail how NAV functions are constructed and learn how to construct your own functions. We will 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 to design efficiently, update and upgrade the system with the goal of helping us to become more productive and high
quality NAV developers.
Appendix, Review Answers, provides you with the answers to the questions given in each chapter.
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. The ideal license is a full Developer's license. If your 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 V2015. 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 these applications
°° Has significant programming experience
°° Has access to a copy of NAV 2015 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 toolset
• 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 the 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 NAV because it is one of the most widely used flexible business application systems available
The reader of this book:
• Does not need to be an expert in object-oriented programming
• Does not need previous experience with NAV, C/AL or C/SIDE