Data Loading...

9781789137798 Flipbook PDF


178 Views
47 Downloads
FLIP PDF 1.51MB

DOWNLOAD FLIP

REPORT DMCA

Programming Microsoft Dynamics 365 Business Central Sixth Edition Build customized business applications with the latest tools in Dynamics 365 Business Central

Mark Brummel, David Studebaker and Chris Studebaker

FOR SALE IN INDIA ONLY

www.packt.com

Programming Microsoft Dynamics 365 Business Central Sixth Edition Build customized business applications with the latest tools in Dynamics 365 Business Central

Mark Brummel David Studebaker Chris Studebaker

BIRMINGHAM - MUMBAI

Programming Microsoft Dynamics 365 Business Central Sixth Edition Copyright © 2019 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 authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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. Commissioning Editor: Richa Tripathi Acquisition Editor: Chaitanya Nair Content Development Editor: Rohit Singh Technical Editor: Romy Dias Copy Editor: Safis Editing Project Coordinator: Vaidehi Sawant Proofreader: Safis Editing Indexer: Priyanka Dhadke Graphics: Alishon Mendonsa Production Coordinator: Aparna Bhagat First published: October 2007 Second edition: November 2009 Third edition: February 2013 Fourth edition: July 2015 Fifth edition: April 2017 Sixth edition: April 2019 Production reference: 1300419 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78913-779-8

www.packtpub.com

mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content

PacktPub.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Contributors About the authors Mark Brummel started working with Navision in 1997 as an end user. He started working for a Navision solution center in 1999 and witnessed the evolution of the product. In 2006, he received the MVP award from Microsoft and started a journey of close involvement in the product. After the migration to Microsoft Dynamics NAV, the three-tier architecture and role-tailored user interface, he became a trusted consultant, frequently visiting the Microsoft Development Center in Copenhagen and speaking at events. Mark was very closely involved in the early ideas of implementing modern programming concepts that are now known as events and extensions. He is currently senior product specialist at ForNAV and a freelance software architect. Working on this book with Dave and Chris has been amazing. I have been involved since the first edition and to see this book stay strong throughout the changes of the product says something about it. It has been a pleasure updating the content to the latest version of the product. I would like to thank Dave and his wife Karen for all the opportunities our friendship has brought and the lessons in life we have been able to share. Of course, I'd like to thank my wife, Dionel, and my kids for giving me the time to work on the book.

David Studebaker has been designing and developing software since 1962 as a developer, consultant, manager, and business owner. In 1967, David coauthored the first generalpurpose SPOOL system, an AT&T / IBM joint project. He has been a founding partner in several firms, most recently Studebaker Technology and Liberty Grove Software. David's publications include a decade of technical reviews for ACM Computing Reviews and a number of articles on shop floor data collection. David originated the Packt series of books on programming Dynamics Business Central (aka Dynamics NAV). He has a BS in mechanical engineering from Purdue University and an MBA from the University of Chicago. He is a life member of the Association for Computing Machinery. I am grateful for the joy of working with Mark and Christopher, my coauthors. I want to thank the many special people who have provided guidance and assistance throughout my life, especially my parents. I am thankful for the love and support of my children, Becky and Chris, their spouses and children. Most of all, I am deeply grateful to Karen, my lifelong partner in marriage, family, business, and love, for her unwavering support in all things.

Chris Studebaker was a certified environmental consultant working with manufacturing facilities to meet national and state regulations before he started working with Navision in 1999. After working on regulatory reporting, data analysis, project management, and subcontractor oversight, Chris has used those skills to sell, develop, and implement NAV for the past 20 years. He has specialized in retail, manufacturing, job shop, and distribution implementations, mostly in high-user-count, high-data-volume applications. Chris acts in a consulting and training role for customers and for peer NAV professionals. He has a Bachelor of Science degree from Northern Illinois University and has done graduate work at Denmark Technical University. This book would not have been possible without Mark and David, and I am extremely grateful for all their work. I would like to thank the many people who have mentored me through the years and am thankful for the many friendships that I've formed, both with team members and customers. The NAV world is full of supportive people, and I am thankful to my parents for introducing me to it. I would like to thank my wife, Beth, and son, Cole, for supporting my writing.

About the reviewers Ronald E. Oates switched university majors from theatre to computer science when he discovered he had a "knack" for programming. It was a good move—in 1979, he got his first programming job as a contract programmer, developing software in COBOL, RPG II, and DEC/VAX BASIC on mainframe and mini computers. In 1986, with the advent of microcomputers, he started Productive Systems, Inc. to focus on bringing software solutions to small and mid-size businesses. Productive Systems, Inc. became a Microsoft Partner in 1997 when the program was started. In 1999, PSI became a Navision Solution Center. Navision perfectly fit Ron’s vision of solutions with existing base functionality that could be rapidly and securely modified to fit individual customer needs. Once Navision was discovered, the focus of the business was entirely Navision, then Microsoft Dynamics NAV, and now Microsoft Business Central 365. Roberto Stefanetti is a functional and technical consultant who has worked on education and training for companies, partners, and clients. He currently works on Microsoft systems, especially ERP and related environments. He started working on Navision in 2004, both as a developer and as a functional consultant, and he is now more involved in consulting and managing projects than in development. He has been an MVP in business application since 2016 and a Microsoft Education Influencer since 2017. Roberto's blog is one of the most widely read in the world (with more than 1 million page visits). He has also published articles on many digital publications (such as MSDynamicsWorld, NAVUG Magazine, and others) and reviewed a number of books.

Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents Preface

1

Chapter 1: Introduction to Business Central Business Central – an ERP system Financial management Manufacturing Supply chain management Business intelligence and reporting Relationship management Human resource management Project management

A developer's overview of Business Central

Business Central object types The Visual Studio Code integrated development environment Visual Studio Code icons Explorer Search Source control Debugger Extensions

AL programming language Business Central object and system elements Business Central functional terminology User interface

Hands-on development in Business Central

Business Central development exercise scenario Getting started with application design Folder structure launch.json app.json

Symbol files Application tables

Designing a simple table Creating a simple table

Pages

Standard elements of pages List pages Card pages Document pages Journal/worksheet pages

Creating a list page

13 14 16 16 17 17 18 18 19 19 19 20 21 22 22 23 24 24 25 27 30 30 32 32 33 34 34 35 35 36 37 38 41 41 42 42 43 44 45

Table of Contents

Creating a card page Creating some sample data Creating a list report Generating the layout Designing the layout

Other Business Central object types TableExtension and PageExtension Codeunits Queries XMLports Control add-ins

Development backups and documentation Summary Questions Chapter 2: Tables An overview of tables Components of a table Naming tables Table numbering Table properties Table triggers Keys SumIndexFields Field groups Bricks

Enhancing our sample application

Creating and modifying tables Assigning a table relation property Assigning an InitValue property Adding a few activity-tracking tables New tables for our WDTU project New list pages for our WDTU project Keys, SumIndexFields, and table relations in our examples Secondary keys and SumIndexFields Table relations

Modifying an original Business Central table

Types of table

Fully modifiable tables

Master data Journal Template Entry tables Subsidiary (supplementary) tables Register Posted document Singleton

[ ii ]

49 50 51 53 56 59 59 60 61 61 62 62 63 63 67 68 69 70 70 71 74 76 79 80 82 83 83 88 90 90 92 96 96 96 97 98 99 100 100 101 102 103 106 108 110 111

Table of Contents

Temporary

Content modifiable tables System table

Read-only tables Virtual

Summary Questions Chapter 3: Data Types and Fields Basic definitions in Business Central Fields Field properties Field triggers Field events Data structure examples Field numbering Field and variable naming

Data types

Fundamental data types Numeric data String data Date/Time data

Complex data types

Data structure Objects Web services DotNet Input/output DateFormula References and other data types

Data type usage

FieldClass property options

FieldClass – Normal FieldClass – FlowField FieldClass – FlowFilter FlowFields and FlowFilter for our application

Filtering

Experimenting with filters Accessing filter controls

Summary Questions Chapter 4: Pages - The Interactive Interface Page design and structure overview Page design guidelines Business Central page structure

Types of pages

[ iii ]

112 113 113 115 115 116 116

119 120 120 121 126 127 127 128 129 130 130 130 132 133 135 135 136 136 136 136 137 142 144 146 146 146 149 151 154 155 162 163 164 167 168 168 169 172

Table of Contents

Role Center page HeadlinePart page List page Card page Document page FastTabs

List Plus page Worksheet (journal) page ConfirmationDialog page StandardDialog page Navigate page Navigate function Request page

Page parts

FactBox area

Card Parts and List Parts

Charts Page names

In-client designer Designer

Page components Page triggers Page properties Inheritance

WDTU page enhancement – part 1 Page controls Control types

Container controls group controls Field controls Page part controls Page control triggers

Bound and unbound pages

WDTU page enhancement – part 2 Page actions Page action types and subtypes Action groups Navigation pane button actions Actions summary

Learning more

Patterns and creative plagiarism Experimenting on your own Experimentation

Summary Questions

[ iv ]

172 174 174 176 176 177 178 179 180 180 181 182 183 183 184 184 185 186 187 188 191 192 193 195 196 200 202 203 203 208 211 212 213 213 215 218 219 221 222 223 223 224 225 227 227

Table of Contents

Chapter 5: Queries and Reports Queries

Building a simple query Query and query component properties Query properties DataItem properties Column properties

Reports

What is a report? Four Business Central report designers Business Central report types Report types summarized Report naming

Report components – overview Report structure

Report data overview Report layout overview

Report data flow

Report components – detail Report properties Microsoft Word – report properties Report triggers Request page properties Request page triggers DataItem properties DataItem triggers

Creating a report in Business Central Learn by experimentation Report building – phase 1 Report building – phase 2 Report building – phase 3

Modifying an existing report with Report Designer or Word

Request page

Adding a request page option

Processing-only reports Creative report plagiarism and patterns

Summary Questions Chapter 6: Introduction to AL Understanding Visual Studio Code Explorer

Starting a new object Object designer navigation Some AL naming conventions Variables AL Globals

[v]

231 232 233 239 239 240 240 241 241 242 244 248 249 249 250 251 252 253 256 256 258 259 260 260 261 263 263 264 264 267 270 273 274 276 279 279 280 281 283 284 284 286 287 288 289 290

Table of Contents AL Locals Special working storage variables

AL programming

Non-modifiable procedures Modifiable procedures Custom procedures Creating a procedure

AL syntax

Assignment and punctuation Expressions Operators

Arithmetic operators and procedures Boolean operators Relational operators and procedures Precedence of operators

Frequently used AL procedures The MESSAGE procedure The ERROR procedure The CONFIRM procedure The STRMENU procedure Record procedures

The SETCURRENTKEY procedure The SETRANGE procedure The SETFILTER procedure The GET procedure

FIND procedures

FIND ([Which]) options and the SQL Server alternatives

Conditional statements

The BEGIN-END compound statement IF-THEN-ELSE statement

Indenting code

Some simple coding modifications Adding field validation to a table Adding code to a report

Laying out the new Report Heading Saving and testing Lookup-related table data Laying out the new report Body Saving and testing

Handling user entered report options Defining the Request Page Finishing the processing code

Testing the completed report

Summary Questions Chapter 7: Intermediate AL IntelliSense Internal documentation

290 291 294 295 295 296 297 299 300 301 302 304 305 305 306 307 308 309 311 312 314 314 315 315 316 317 318 321 321 321 322 323 323 327 328 328 329 330 330 331 333 333 334 336 336 339 340 341

[ vi ]

Table of Contents

Source code management Validation functions TESTFIELD FIELDERROR INIT VALIDATE

Date and time functions

TODAY, TIME, and CURRENTDATETIME WORKDATE DATE2DMY function DATE2DWY function DMY2DATE and DWY2DATE functions CALCDATE

Data conversion and formatting functions ROUND FORMAT function EVALUATE function

FlowField and SumIndexField functions CALCFIELDS function SETAUTOCALCFIELDS function CALCSUMS function

Comparing CALCFIELDS and CALCSUMS

Flow control functions

REPEAT-UNTIL WHILE-DO FOR-TO or FOR-DOWNTO CASE-ELSE statement WITH-DO statement QUIT, BREAK, EXIT, and SKIP functions QUIT function BREAK function EXIT function SKIP function

Input and output functions

NEXT function with FIND or FINDSET INSERT function MODIFY function Rec and xRec

DELETE function MODIFYALL function DELETEALL function

Filtering

The SETFILTER function The COPYFILTER and COPYFILTERS functions The GETFILTER and GETFILTERS functions

[ vii ]

343 344 344 345 347 347 348 348 349 351 351 351 352 353 354 355 356 356 358 359 359 360 361 361 362 362 363 365 366 366 367 367 367 368 368 369 370 370 370 371 372 372 373 374 374

Table of Contents

The FILTERGROUP function The MARK function CLEARMARKS function The MARKEDONLY function The RESET function

InterObject communication

Communicating through data Communicating through function parameters Communication via object calls

Enhancing the WDTU application Modifying table fields Adding validation logic

Playlist Header validation

Creating the Playlist subpage Playlist Line validations

Creating a function for our FactBox Creating a FactBox page

Summary Questions Chapter 8: Advanced AL Development Tools Business Central process flow Initial setup and data preparation Transaction entry Testing and posting the Journal batch Utilizing and maintaining the data Data maintenance

Role Center pages

Role Center structure

Role Center headlines page Role Center activities page Cue groups and cues

System part Page parts

Page parts not visible Page parts for user data

Navigation pane and action menus

Action Designer Creating a WDTU Role Center ribbon

XMLports

XMLport components

XMLport properties XMLport triggers XMLport data lines The XMLport line properties SourceType as text SourceType as table

[ viii ]

375 376 376 376 377 377 377 378 378 379 380 382 382 384 387 390 392 395 396 399 400 402 402 402 403 404 404 404 407 408 408 412 412 414 414 415 417 418 420 422 422 425 426 427 428 428

Table of Contents SourceType as field

Element or attribute

NodeType element data item NodeType attribute data item

XMLport line triggers

DataType as text DataType as Table DataType as Field

XMLport Request Pages

Web services

Exposing a web service Publishing a web service Enabling web services Determining what was published XMLport – web services integration example for WDTU

Summary Questions Chapter 9: Successful Conclusions Creating new AL routines Callable functions

Codeunit 358 – DateFilterCalc Codeunit 359 – Period Form Management FindDate function NextDate function CreatePeriodFormat function

Codeunit 365 – Format Address Codeunit 396 – NoSeriesManagement Function models to review and use

Management codeunits

Multi-language system Multi-currency system Navigate Modifying for Navigate

Debugging in Business Central

Dialog function debugging techniques

Debugging with MESSAGE and CONFIRM Debugging with DIALOG Debugging with text output Debugging with ERROR

The Business Central debugger Activating the debugger Creating break events The debugger window

Visual Studio Code test-driven development Other interfaces Client Add-ins Client Add-in comments

[ ix ]

429 430 430 430 430 430 431 431 432 432 434 435 436 436 439 443 443 447 448 449 449 451 451 452 453 453 455 456 457 458 459 460 462 463 464 464 465 466 466 467 467 468 469 470 473 474 475

Programming Microsoft Dynamics 365 Business Central – Sixth Edition Microsoft Dynamics 365 Business Central is a full ERP business solution suite with a robust set of development tools to support customization and enhancement. These tools can be used to tailor Business Central's in-built applications to support complete management functions for finance, supply chain, manufacturing, and operations.

learn how to evaluate a product's development capabilities and manage Business Central-based development and implementation. You'll explore application structure, the construction of and uses for each object type, and how it all fits together to build apps that meet special business requirements.

Using a case study approach, this book will introduce you to Dynamics 365 Business Central and Visual Studio Code development tools to help you become a productive Business Central developer. You'll also

By the end of this book, you'll understand how to design and develop high-quality software using the Visual Studio Code development environment, the AL language paired with the improved editor, patterns, and features.

Things you will learn: •

Programming using the AL language in the Visual Studio Code development environment



Explore functional design and development using AL



How to build interactive pages and learn how to extract data for users



How to use best practices to design and develop modifications for new functionality integrated with the standard Business Central software



Become familiar with deploying the broad range of components available in a Business Central system



Create robust, viable systems to address specific business requirements

www.packt.com

FOR SALE IN INDIA ONLY