Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Learning Dynamics NAV Patterns
Learning Dynamics NAV Patterns
Learning Dynamics NAV Patterns
Ebook488 pages2 hours

Learning Dynamics NAV Patterns

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Learning Dynamics NAV Patterns is intended for developers, architects, (technical) consultants, and application managers. You may have very little or no knowledge of NAV patterns, but you should be acquainted with programming.
LanguageEnglish
Release dateSep 24, 2015
ISBN9781783552566
Learning Dynamics NAV Patterns

Read more from Mark Brummel

Related to Learning Dynamics NAV Patterns

Related ebooks

Programming For You

View More

Related articles

Reviews for Learning Dynamics NAV Patterns

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    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

    Enjoying the preview?
    Page 1 of 1