Learning Dynamics NAV Patterns
By Mark Brummel
()
About this ebook
Read more from Mark Brummel
Programming Microsoft Dynamics 365 Business Central - Sixth Edition: Build customized business applications with the latest tools in Dynamics 365 Business Central, 6th Edition Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics NAV 2013 Application Design Rating: 0 out of 5 stars0 ratingsProgramming Microsoft Dynamics NAV - Fifth Edition Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics NAV 2009 Application Design Rating: 0 out of 5 stars0 ratings
Related to Learning Dynamics NAV Patterns
Related ebooks
Microsoft Dynamics NAV 2015 Professional Reporting Rating: 1 out of 5 stars1/5Programming Microsoft Dynamics® NAV 2013 Rating: 0 out of 5 stars0 ratingsOdoo 10 Development Essentials Rating: 0 out of 5 stars0 ratingsBuilding ERP Solutions with Microsoft Dynamics NAV Rating: 0 out of 5 stars0 ratingsMastering Microsoft Dynamics NAV 2016 Rating: 4 out of 5 stars4/5Oracle Business Intelligence Enterprise Edition 12c - Second Edition Rating: 0 out of 5 stars0 ratingsLearning SAP BusinessObjects Dashboards Rating: 0 out of 5 stars0 ratingsExtending Microsoft Dynamics 365 for Operations Cookbook Rating: 5 out of 5 stars5/5Implementing Microsoft Dynamics NAV - Third Edition Rating: 0 out of 5 stars0 ratingsSAP Business ONE Implementation Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics GP 2013 Implementation Rating: 0 out of 5 stars0 ratingsOracle Information Integration, Migration, and Consolidation Rating: 0 out of 5 stars0 ratingsApplied Architecture Patterns on the Microsoft Platform Rating: 0 out of 5 stars0 ratingsIBM Cognos TM1 Developer's Certification guide Rating: 0 out of 5 stars0 ratingsGetting Started with Oracle Data Integrator 11g: A Hands-On Tutorial Rating: 5 out of 5 stars5/5MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics CRM 2016 Customization - Second Edition Rating: 0 out of 5 stars0 ratingsForce.com Enterprise Architecture - Second Edition Rating: 1 out of 5 stars1/5Programming Microsoft Dynamics™ NAV 2015 Rating: 0 out of 5 stars0 ratingsApplied Architecture Patterns on the Microsoft Platform Second Edition Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics AX 2009 Development Cookbook Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics AX Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics AX 2012 Reporting Cookbook Rating: 0 out of 5 stars0 ratingsLearning BPMN 2.0: An Introduction of Engineering Practices for Software Delivery Teams Rating: 0 out of 5 stars0 ratingsIdentity Access Management A Complete Guide - 2021 Edition Rating: 0 out of 5 stars0 ratingsGetting Started with Dynamics NAV 2013 Application Development Rating: 0 out of 5 stars0 ratingsInformation Structure Design for Databases: A Practical Guide to Data Modelling Rating: 5 out of 5 stars5/5Functional Requirement A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsSoftware Design Pattern A Complete Guide - 2020 Edition Rating: 0 out of 5 stars0 ratingsInstant Pentaho Data Integration Kitchen Rating: 0 out of 5 stars0 ratings
Programming For You
HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsLearn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5The Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsCoding All-in-One For Dummies Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratingsSQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5The Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5Teach Yourself C++ Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Web Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5
Reviews for Learning Dynamics NAV Patterns
0 ratings0 reviews
Book preview
Learning Dynamics NAV Patterns - Mark Brummel
Table of Contents
Learning Dynamics NAV Patterns
Credits
Foreword
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Instant updates on new Packt books
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introducing Dynamics NAV Patterns and Software Architecture
What do we mean by 'patterns'?
Software design patterns
The Procedural software design patterns
Microsoft Dynamics NAV Design Patterns
The object-oriented patterns
Non-object-oriented patterns
The functional oriented patterns
Patterns elements and hierarchy
Architectural patterns
Design patterns
Structuring code
The coding standards
Anti-patterns
Code cloning
Legacy code
Upgradability
The upgrade frequency
Design patterns and upgrades
Delta files
Repeatability
Design patterns and repeatability
Lifecycle of a design pattern
Technology changes
Old habits die hard
New design patterns
Software architecture in Microsoft Dynamics NAV
Metadata
Building blocks
Table
Page
Report
Codeunit
Query
XMLPort
MenuSuite
Metadata
Flowfields
Flowfilters
Base application
Functional processes
Summary
2. Architectural Patterns
The Singleton Pattern
Technical description
Company-Initialize
Implementations
Examples
Enhancements
The Supplemental and Subsidiary Pattern
Technical description
Implementations
Examples
The Compound Pattern
Technical description
Implementation
Examples
The Rules Pattern
Technical description
Implementations
Examples
The Master Data Pattern
Technical description
Implementations
Examples
The Journal Template-Batch-Line Pattern
Technical description
The Journal Template table
The Journal Batch table
The Journal Line table
Recurring Journals
Pages
Codeunits
Implementations
Hierarchy
Journals as contracts
Examples
The Entry Pattern
Technical description
The Entry Table types
Historical entries
Temporary entries
Entries that can be deleted
Temporary tracking buckets
Implementations
Examples
Document Pattern
Technical description
The Header table
The Line table
Posting and archiving
Implementations
Examples
The Argument table
Technical description
Implementations
Summary
3. Design Patterns
The Entity State Pattern
Technical description
Setting the State
Testing the State
Implementations
Examples
The Select Pattern
Technical description
Implementations
Examples
The Number Series Pattern
Technical description
The Table reference field
Setup reference
C/AL functions and variables
Implementations
Examples
Address Integration Pattern
Technical description
Fields
Copying the address
Printing addresses
Implementations
Examples
Multi-Level Setup
Technical description
Implementations
Examples
Document History
Technical description
The naming conventions
Codeunit Structure
Test Near, Test Far
Do it
Clean up
An Example
TRANSFERFIELDS
Implementations
Examples
Copy Document Pattern
Technical description
Validation logic
Implementations
Examples
Job Queue Entry Pattern
Technical description
Preprocessing
Getting records
The Main function
Post-processing
Error handling
Implementations
Examples
Dismissible dialogs and save preferences
Technical description
Dismissible dialog
Implementations
Examples
Setup Update Pattern
Technical description
Restrictions
Implementations
Example
Model-View ViewModel Pattern
Technical description
Implementations
Examples
Summary
4. Building an Example Application Using Patterns
The design elements
The Pattern dependencies
Step one – Foundation
Example setup
Which Patterns to use
The implementation
The Multi-Level Setup Pattern
Step two – Master Data
Example Person
The Example Product
Number Series
Adding Setup fields
Adding variables
Adding the No. Series field
Code snippets
Entity State
Implementing the Address Integration Pattern
Step three – Journals & Entries
Creating your own Journal and Entry
Validation in Journals
Step four – Documents
Implementing a Document
Document history
Selecting a Pattern
Other Patterns
Posting
The ThrowErrorIfNoSelection function
The TestNear function
The TestFar function
The PostExampleOne/PostExampleTwo function
The PostExJnlLine function
The DeleteExampeDocument function
The layered model
Summary
5. Coding Best Practices
Coding guidelines
Code design
Variable capacity
The Cyclomatic Complexity
The function size
Using complex data types
Localizability
Date formulas
Code readability
Variable naming
Self-explaining
Suffix versus prefix
Approved abbreviations
Class-Method-Property
The Table as a class
A Codeunit as a method
Function libraries and interfaces
Natural Language Programming
Pitfalls
Bonus – debugging
Encapsulation
Override Functions
Façade
Hooks
Disabling the original source code
Predefined hooks
Variant variables
Managing DLL
Summary
6. Anti-patterns and Handling Legacy Code
Anti-patterns
Code cloning
Forking
Templating
Customizing
Exact match
Examples
Transaction mirroring
Code normalization and writing clean code
The Document type normalization
The small business application
The VAT and Sales Tax calculation
Avoiding code cloning
Boat anchors
Other anti-patterns and context
Programming language capabilities
Legacy code
Refactoring the C/AL Code
Refactoring tables
Renaming
Normalization
Code refactoring
Finding the process owner
Moving to Codeunit
Breaking down the code into functions
Encapsulating functions
Normalizing the code
The boy scout rule
Summary
7. Building Solutions Using Patterns
Building blocks
Applying Architectural Patterns
The application setup
Guests
Room
Season
Price
Reservation
Stay
Check-in
Check-out
Clean
Evaluation
Invoice
Creating the Table objects
Applying Design Patterns
The Bed and Breakfast setup
Bed and Breakfast season
Bed and Breakfast room
Bed and Breakfast price
Bed and Breakfast clean entry
Bed and Breakfast stay
Bed and Breakfast journal and entry
The Bed and Breakfast evaluation header and evaluation line
Defining the methods
Writing the Code and Link methods
Creating the cleaning entries
Refactoring
The new class members
The new function library
Room members
The room price calculation
Testing the application
Test isolation
Analyzing the results
Upgrading the application
Creating a Delta file
The steps of creating a Delta file
Inside the Delta file
Building our application
Building the result
Managing the source code
Creating the workspace
Setting up Visual Studio
Uploading the files
Summary
Index
Learning Dynamics NAV Patterns
Learning Dynamics NAV Patterns
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2015
Production reference: 1210915
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-419-9
www.packtpub.com
Credits
Author
Mark Brummel
Reviewers
Alex Chow
Luc Van Dyck
Alain Krikilion
Rakesh Raul
Daniel Rimmelzwaan
Bill Warnke
Commissioning Editor
Kunal Parikh
Acquisition Editor
Tushar Gupta
Content Development Editor
Priyanka Mehta
Technical Editor
Rohith Rajan
Copy Editor
Yesha Gangani
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Tejal Soni
Graphics
Sheetal Aute
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
Foreword
One of the many things that make Microsoft Dynamics NAV unique is that it is fully customizable and extendable. The ERP application, shipped by Microsoft as a part of NAV, is completely customizable and extendable using the traditional raw source code modification, or using the events as of Microsoft Dynamics NAV 2016. This makes the product extremely flexible and adored by the SMB market.
NAV has been built to focus on simplicity. It has been built with a strong belief that the application developer need not know all about the technical domain, like transaction isolation, advanced error recovery, database locks, memory allocations, and so on, but instead, should be able to unleash his or her domain skills. In short, write the happy path code and leave the rest to the NAV—no more, no less. I still believe that these principles hold their value and lately, we can add web-services, cloud, devices, and other new terms to the list of challenges that Microsoft Dynamics NAV handles behind the scenes almost like magic.
The application that is shipped with Microsoft Dynamics NAV has been designed by keeping simplicity and extendability in mind. The simple yet powerful syntax of the the application language, the ability to copy and paste parts of the application and reuse it in a different way, has always been a part of the Microsoft Dynamics NAV DNA. Although copying and pasting, from a purely engineering perspective, could be considered bad practice, it has proven itself very productive over the years.
Over a period of time, many Patterns that are found in today's application have evolved naturally. Many of them were first used in the character-based version, upgraded to the Windows client, and then later to the current three-tier architecture. While the adherence to and use of such Patterns is purely optional for developers, multiple reasons exist to follow the recommended Patterns and guidelines—the code will typically be easier to test and easier to upgrade, just to mention two.
By following some guidelines and principles, the sharing of application code in a large and growing community will also benefit tremendously. It might be as simple as consequent variable naming when writing code, or consistent naming of fields and tables when designing the data model.
I believe that small things like identifying recurring Patterns and assigning names to these can enhance communication, and create a common syntax between developers. It allows the community to discuss best practices, and improve and share design. This is very important, since downstream it allows the design of extensions that are easy to merge, have a lower maintenance cost, and allow easier implementation of additional changes.
Using common guidelines and best practices make it easier to work together and share code in an ecosystem that is dynamic and spans across the globe.
This is what makes Patterns unique and powerful—just like NAV itself.
Thomas Hejlsberg
Chief Architect
Microsoft Dynamics NAV
August 2015
About the Author
Mark Brummel is a freelance all-round Microsoft Dynamics NAV specialist, focused on helping end users of the product.
With http://nav-skills.com/, he evangelizes and documents the 'NAV way'. This is a combination of architectural principles and design best practices, formalized in a workshop called Master Class for Microsoft Dynamics NAV Application Architecture and Design Patterns. The methodology helps in creating solutions that are easy to upgrade, recognizable for users, and maintainable outside the ecosystem of their creators. All three elements apply to the original Navision product that was shipped in 1995, and was extracted, updated, and documented in this methodology. In September 2015, Packt Publishing published his new book, Learning Dynamics NAV Patterns, which is about this methodology. He also organizes hands-on workshops together with a group of MVPs and MCTs from across the globe.
Mark started in 1997 as an end user, and worked for 8 years for the NAV partners after this. Designing and maintaining add-on systems was his specialization. Some of these add-on systems exceed the standard product, when it comes to size and complexity. Coaching colleagues and troubleshooting complex problems is his passion and part of his day-to-day work. His first book, Dynamics NAV 2009 Application Design, was published in 2010 by Packt Publishing, and updated to Dynamics NAV 2013 Application Design, published by Packt Publishing, when a new release became available.
Many end users of Microsoft Dynamics NAV struggle with the question of how to upgrade their two-tier solution to a three-tier solution. Mark can help you answer these questions and plot a roadmap to the future, retaining the investment in the solution.
When Microsoft introduced the three-tier architecture in 2009, it meant a major shift for experienced NAV developers and consultants. Mark has trained most of those that live in the Netherlands and Belgium.
In 2010, he started a think tank called Partner Ready Software together with four other Dynamics NAV experts. Partner Ready Software brings fresh ideas about designing applications in NAV, and creates awareness of applying Design Patterns in creating repeatable solutions.
Mark is an associate in the Liberty Grove Software network, a member of the NAVUG advisory board, the co-founder of the Dutch Dynamics Community, the vice-president of the Association of Dynamics Professionals, and an advisor to Dynamics HUB.
Mark has undertaken a special project and performance tuning of the Dynamics NAV product on SQL Server. As a unique specialist, he has done breakthrough research into improving the performance of Dynamics NAV on the SQL Server.
On http://nav-skills.com/, Mark maintains a blog. This blog contains a wide range of articles about both the Microsoft Dynamics NAV and the SQL Server product. He is also a frequent speaker at Microsoft events, and publishes articles on Pulse for LinkedIn.
Since 2006, Mark has been rewarded by Microsoft with the Most Valuable Professional award for his contribution to the online and offline communities. He has received this award ten times.
Mark is married and a father of four, and lives in a small town in The Netherlands.
Acknowledgement
This book is the result of working with Microsoft Dynamics