Microsoft Dynamics AX 2012 Development Cookbook - Mindaugas Pocius - E-Book

Microsoft Dynamics AX 2012 Development Cookbook E-Book

Mindaugas Pocius

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Microsoft Dynamics AX is a comprehensive Enterprise Resource Planning (ERP) solution for mid-size and large organizations. Dynamics AX implementations are used worldwide by thousands of customers. With the new version - Dynamics AX 2012 - the system is due to expand even more rapidly.
Every new implementation requires some level of customization, and all organizations want this to be done to the highest standards using proven approaches.
Written by one of the leading experts in Microsoft Dynamics AX, 'Microsoft Dynamics AX 2012 Development Cookbook' is packed with over 80 task-based and immediately reusable recipes that will help you manage your company's or customer's ERP information and operations efficiently, and solve your business process problems in an effective and quick way. This book focuses on commonly used custom modifications in major Dynamics AX modules. The recipes in this book cover various areas of Dynamics AX to help developers not only learn about programming, but also about the functional side of Dynamics AX. The practical recipes will also allow you to look at the development from the perspective of business processes. You will learn to enhance your user interface using various Dynamics AX UI elements and managing your data and functions will become easier.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 323

Veröffentlichungsjahr: 2012

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Microsoft Dynamics AX 2012 Development Cookbook
Credits
About the Author
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
Errata
Piracy
Questions
1. Processing Data
Introduction
Creating a new number sequence
How to do it...
How it works...
See also
Renaming the primary key
How to do it...
How it works...
Merging two records
How to do it...
How it works...
Adding a document handling note
How to do it...
How it works...
Using a normal table as a temporary table
How to do it...
How it works...
Copying a record
How to do it...
How it works...
There's more...
Building a query object
How to do it...
How it works...
There's more...
Using the OR operator
Using arrays fields
See also
Using a macro in an SQL statement
How to do it...
How it works...
Executing a direct SQL statement
How to do it...
How it works...
There's more...
Enhancing the data consistency check
Getting ready
How to do it...
How it works...
There's more...
Exporting data to an XML file
How to do it...
How it works...
Importing data from an XML file
How to do it...
How it works...
Creating a comma-separated value file
How to do it...
How it works...
There's more...
Reading a comma-separated value file
How to do it...
How it works...
There's more...
Using the date effectiveness feature
How to do it...
How it works...
There's more...
2. Working with Forms
Introduction
Creating a dialog
How to do it...
How it works...
See also
Handling a dialog event
How to do it...
How it works...
There's more...
See also
Building a dynamic form
How to do it...
How it works...
Adding a form splitter
How to do it...
How it works...
Creating a modal form
How to do it...
How it works...
There's more...
See also
Modifying multiple forms dynamically
How to do it...
How it works...
Storing last form values
How to do it...
How it works...
Using a tree control
How to do it...
How it works...
There's more...
Performance
Drag-and-drop
See also
Building a checklist
How to do it...
How it works...
There's more...
Adding the View details link
How to do it...
How it works...
3. Working with Data in Forms
Introduction
Using a number sequence handler
How to do it...
How it works...
See also
Creating a custom filter
How to do it...
How it works...
See also
Creating a custom instant search filter
How to do it...
How it works...
See also
Building a selected/available list
How to do it...
How it works...
There's more...
Preloading images
How to do it...
How it works...
There's more...
See also
Creating a wizard
How to do it...
How it works...
Processing multiple records
How to do it...
How it works...
Coloring records
How to do it...
How it works...
Adding an image to records
How to do it...
How it works...
There's more...
Displaying an image as part of a form
Saving a stored image as a file
4. Building Lookups
Introduction
Creating an automatic lookup
How to do it...
How it works...
There's more...
Creating a lookup dynamically
How to do it...
How it works...
Using a form for building a lookup
How to do it...
How it works...
See also
Building a tree lookup
How to do it...
How it works...
See also
Displaying a list of custom options
How to do it...
How it works...
There's more...
Another way of displaying custom options
How to do it...
How it works...
There's more...
Building a lookup based on record description
How to do it...
How it works...
There's more...
Building the Browse for Folder lookup
How to do it...
How it works...
There's more...
Manual folder browsing lookup
Adding a Make New Folder button
Building a lookup for selecting a file
How to do it...
How it works...
There's more...
Creating a color picker lookup
How to do it...
How it works...
There's more...
5. Processing Business Tasks
Introduction
Using a segmented entry control
How to do it...
How it works...
There's more...
See also
Creating a general journal
How to do it...
How it works...
There's more
See also
Posting a general journal
How to do it...
How it works...
See also
Processing a project journal
How to do it...
How it works...
There's more...
Creating and posting a ledger voucher
How to do it...
How it works...
See also
Changing an automatic transaction text
Getting ready
How to do it...
How it works...
There's more...
Creating a purchase order
How to do it...
How it works...
See also
Posting a purchase order
How to do it...
How it works...
There's more...
Creating a sales order
How to do it...
How it works...
See also
Posting a sales order
How to do it...
How it works...
There's more...
Creating an electronic payment format
How to do it...
How it works...
6. Integration with Microsoft Office
Introduction
Creating an Excel file
How to do it...
How it works...
Reading an Excel file
How to do it...
How it works...
Creating a Word document from a template
Getting ready
How to do it...
How it works...
Creating a Word document with repeating elements
Getting ready
How to do it...
How it works...
Creating a Microsoft Project file
Getting ready
How to do it...
How it works...
Sending an e-mail using Outlook
Getting ready
How to do it...
How it works...
7. Using Services
Introduction
Consuming the system query service
How to do it...
How it works...
Consuming the system metadata service
How to do it...
How it works...
Consuming an existing document service
How to do it...
How it works...
There's more
Creating a document service
How to do it...
How it works...
Consuming a document service
How to do it...
How it works...
See also
Using an enhanced document service
How to do it...
How it works...
See also
Creating a custom service
How to do it...
How it works...
See also
Consuming a custom service
How to do it...
How it works...
See also
Consuming an external service
How to do it...
How it works...
See also
8. Improving Development Efficiency
Introduction
Creating an editor template
How to do it...
How it works...
Modifying the Tools menu
How to do it...
How it works...
Modifying the right-click context menu
How to do it...
How it works...
Searching for an object in a development project
How to do it...
How it works...
See also
Modifying the Personalization form
How to do it...
How it works...
Modifying the application version
How to do it...
How it works...
9. Improving Dynamics AX Performance
Introduction
Calculating code execution time
How to do it...
How it works...
There's more...
Writing efficient SQL statements
How to do it...
How it works...
Caching a display method
How to do it...
How it works...
Using Dynamics AX Trace Parser
How to do it...
How it works...
See also
Using SQL Server Database Engine Tuning Advisor
How to do it...
How it works...
See also
Index

Microsoft Dynamics AX 2012 Development Cookbook

Microsoft Dynamics AX 2012 Development Cookbook

Copyright © 2012 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: December 2009

Second edition: May 2012

Production Reference: 1270412

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-84968-464-4

www.packtpub.com

Cover Image by David Gutierrez (<[email protected]>)

Credits

Author

Mindaugas Pocius

Reviewers

Angela McClelland

Yev Taranovs

Acquisition Editor

Kerry George

Lead Technical Editor

Meeta Rajani

Azharuddin Sheikh

Technical Editors

Merin Jose

Lubna Shaikh

Mehreen Shaikh

Copy Editor

Brandt D'Mello

Project Coordinators

Alka Nayak

Proofreader

Kelly Hutchinson

Indexer

Tejal Daruwale

Rekha Nair

Hemangini Bari

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Author

Mindaugas Pocius is currently a freelance Dynamics AX technical and functional consultant and trainer at DynamicsLab Limited (www.dynamicslab.com). The company specializes in providing development, consulting, and training services for Microsoft Dynamics AX resellers and customers.

Mindaugas started his IT consulting career back in 2001 while still in his Information Technology Master Studies at a Lithuanian university. Since then he has become a recognized Microsoft Certified Professional for AX in all major areas: Development, Configuration and Installation, Financials, Projects, and Trade and Logistics. He is also a Certified Microsoft Trainer for Dynamics AX and has delivered numerous Dynamics AX training courses across Europe.

From 2001 to 2012, Mindaugas has participated in over 20 Dynamics AX implementations. He has had a wide range of development, consulting, and leading roles, while always maintaining a significant role as a business application developer.

In December 2009, Mindaugas released his first book, "Microsoft Dynamics AX 2009 Development Cookbook", Packt Publishing, which is the predecessor of this book.

First of all, I would like to thank my wife Rasa and my two boys Dominykas and Augustas for their support and understanding during my long hours spent on this book. I also want to apologize for the time I have stolen from them to make this book real.

Secondly, I wish to thank the reviewers—Angela and Yev—my colleagues, very experienced Dynamics AX developers, and good friends.

And lastly, special thanks should be given to the Packt Publishing team who made this book possible.

About the Reviewers

Angela McClelland is a Software Developer and Technical Consultant for Dynamics AX (AX) currently working as a freelance consultant in the United Kingdom.

Angela began working with AX in 2001, while completing a Computer Science degree at The University of Waikato in New Zealand. After a successful implementation of version 2.5, and a later upgrade to 3, the spouse and bags were packed up and moved over to England to seek out bigger project challenges, and for a taste of world travel.

Since this move, Angela has worked on many AX implementations, specializing in business solutions design, X++ programming, reporting, and business intelligence. She is a Microsoft Certified Professional for AX: Development, Installation and Configuration, as well as key modules: Finance, Projects, Production, and Trade and Logistics. She is also a Microsoft Certified Trainer for AX.

A big thanks to Mindaugas for his efforts in writing this book, and for inviting me to be one of the reviewers. I have learned a lot, and already have plans to make use of some of these handy recipes.

Yev Taranovs is an experienced Dynamics AX consultant. Yev has been working with AX since 2002 and has a wide angle of expertise, both technical and functional. Apart from Dynamics AX, Yev is also working with other Microsoft technologies including Microsoft CRM, SharePoint, Reporting Services, Analysis Services, and Visual Studio.

Yev's home town is Riga, Latvia. He started his Dynamics career there and moved to the United Kingdom in 2005. Yev is currently working for Hitachi Solutions.

www.PacktPub.com

Support files, eBooks, discount offers and more

You might want to visit www.PacktPub.com for support files and downloads related to your book.

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.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print and bookmark contentOn demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

Instant Updates on New Packt Books

Get notified! Find out when new books are published by following @PacktEnterprise on Twitter, or the Packt Enterprise Facebook page.

Preface

As a Dynamics AX developer, your responsibility is to deliver all kinds of application customizations, whether it is a small adjustment or a bespoke module. Dynamics AX is a highly customizable system and requires a significant amount of knowledge and experience to deliver quality solutions. One goal can be achieved in multiple ways and there is always the question of which way is the best.

This book takes you through numerous recipes to help you with daily development tasks. Each recipe contains detailed step-by-step instructions along with application screenshots and in-depth explanations. The recipes cover multiple Dynamics AX modules, so at the same time the book provides an overview of the functional aspects of the system for developers.

What this book covers

Chapter 1, Processing Data, focuses on data manipulation. It explains how to build data queries, how to check and modify existing data, how to read and write external files, and how to use date effectiveness.

Chapter 2, Working with Forms, covers various aspects of building forms in Dynamics AX. In this chapter, dialogs and their events are explained. Also, various useful features such as splitters, tree controls, checklists, and others are explained.

Chapter 3, Working with Data in Forms, basically supplements the previous chapter and explains data organization in forms. Examples in this chapter include instructions on how to build form data filters, process multiple records, and work with images and colors.

Chapter 4, Building Lookups, covers all kinds of lookups in the system. The chapter starts with a simple automatically-generated lookup, continues with more advanced ones, and finishes with standard Windows lookups such as the file selection dialog and color picker.

Chapter 5, Processing Business Tasks, explains the usage of the Dynamics AX business logic API. In this chapter, we cover topics on how to process journals, purchase orders, and sales orders. Other features such as modifying transaction text and creating electronic payment formats are included too.

Chapter 6, Integration with Microsoft Office, shows how Word, Excel, Outlook, and Microsoft Project applications could be integrated with Dynamics AX.

Chapter 7, Using Services, explains how to use services in Dynamics AX. The chapter covers standard query, metadata, and document system services. It also demonstrates how to create custom services and how to consume external services.

Chapter 8, Improving Development Efficiency, presents a few ideas about how to make daily development tasks easier. This chapter demonstrates how to build code templates, modify the tools and the right-click context menus, use search in development projects, and how to customize the personalization form.

Chapter 9, Improving Dynamics AX Performance, discusses how system performance could be improved by following several simple rules. This chapter explains how to calculate code execution time, how to write efficient SQL statements, how to properly cache display methods, and how to use Dynamics AX Trace Parser and SQL Server Database Engine Tuning Advisor.

What you need for this book

All coding examples were done using a virtual Microsoft Dynamics AX 2012 Image from the Microsoft Learning Download Center. The following list of software from the virtual image was used in this book:

Microsoft Dynamics AX 2012 (kernel: 6.0.947.0, application: 6.0.593.0)Microsoft Dynamics AX Trace Parser (version: 6.0.947.0)Microsoft Windows Server 2008 R2 EnterpriseMicrosoft SQL Server 2008 R2Microsoft Office Excel 2010Microsoft Office Word 2010Microsoft Office Outlook 2010Microsoft Office Project 2010Microsoft Visual Studio 2010Microsoft Internet Explorer 8Notepad

Although all recipes were tested on the mentioned software, they might work on older or newer software versions without any implications or with minor code adjustments.

Who this book is for

This book is for Dynamics AX developers primarily focused on delivering time proven application modifications. Although new X++ developers could use this book alongside their beginner guides, this book is more focused on people who are willing to raise their programming skills above beginner level and at the same time learn functional aspects of Dynamics AX. So, some Dynamics AX coding experience is expected.

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 <[email protected]>, and mention the book title through 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 to our website, or added to any list of existing errata, under the Errata section of that title.

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 <[email protected]> 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 <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Processing Data

In this chapter, we will cover the following topics:

Creating a new number sequenceRenaming the primary keyMerging two recordsAdding a document handling noteUsing a normal table as a temporary tableCopying a recordBuilding a query objectUsing a macro in an SQL statementExecuting a direct SQL statementEnhancing the data consistency checkExporting data to an XML fileImporting data from an XML fileCreating a comma-separated value fileReading a comma-separated value fileUsing the date effectiveness feature

Introduction

This chapter focuses on data manipulation exercises. Here, we will discuss how to work with query objects from X++ code. We will also discuss how to reuse macros in X++ SQL statements and how to send SQL statements directly to the database. This chapter will explain how to rename primary keys, how to merge and copy records, how to add document handling notes to selected records, and how to create and read XML and comma-separated files. The chapter ends with a recipe about the date effectiveness feature.

Creating a new number sequence

Number sequences in Dynamics AX are used to generate specifically formatted numbers for record identification. It could be anything from voucher numbers or transaction identification numbers to customer or vendor accounts.

When developing custom functionality, very often one of the tasks is to add a new number sequence to the system to support newly created tables. Dynamics AX contains a list of NumberSeqApplicationModule derivative classes, which holds the number sequence setup data for the specific module.

These classes are read by the number sequence wizard, which detects existing number sequences and proposes to create the missing ones or newly added ones. The wizard is normally run as part of the application initialization. It can also be rerun at any time later when expanding the Dynamics AX functionality used, where a setup of additional number sequences is required. The wizard also has to be rerun if new custom number sequences are added to the system.

In this recipe, we will add a new number sequence to the system. In a standard application, the customer group number is not driven by any number sequence, so we will enhance this by creating it.

How to do it...

Carry out the following steps in order to complete this recipe:

Open the NumberSeqModuleCustomer class in the Application Object Tree (AOT), and add the following code to the bottom of the loadModule() method:

Tip

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.

datatype.parmDatatypeId(extendedTypeNum(CustGroupId)); datatype.parmReferenceHelp("Customer group ID"); datatype.parmWizardIsContinuous(false); datatype.parmWizardIsManual(NoYes::No); datatype.parmWizardIsChangeDownAllowed(NoYes::Yes); datatype.parmWizardIsChangeUpAllowed(NoYes::Yes); datatype.parmWizardHighest(999); datatype.parmSortField(20); datatype.addParameterType( NumberSeqParameterType::DataArea, true, false); this.create(datatype);
Create a new job with the following code and run it:
static void NumberSeqLoadAll(Args _args) { NumberSeqApplicationModule::loadAll(); }
Run the number sequence wizard by clicking on the Generate button in Organization administration | Common | Number sequences | Number sequences, and click on the Next button, as shown in the following screenshot:Click on Details to view more information. Delete everything apart from the lines where Area is Accounts receivable and Reference is Customer group. Note the number sequence codes, and click on the Next button:On the last page, click on the Finish button to complete the set up:The newly created number sequences can now be found in Organization administration | Number sequences | Number sequences, as shown in the following screenshot:Open Organization administration | Number sequences | Segment configuration and notice the new Customer group reference:Open Accounts receivable | Setup | Accounts receivable parameters and go to the Number sequences tab page. Here we should see the new number sequence code:The last thing to do is to create a helper method for this number sequence. Locate the CustParameters table in the AOT and create the following method:
public server static NumberSequenceReference numRefCustGroupId() { return NumberSeqReference::findReference( extendedTypeNum(CustGroupId)); }

How it works...

We start the recipe by adding a number sequence initialization code into the NumberSeqModuleCustomer class. As we can understand from its name, it holds the initialization of all number sequences that belong to the Accounts receivable module.

The code in the loadModule() method defines the default number sequence settings to be used in the wizard, such as data type, description, highest possible number, and so on. Additional options, such as starting sequence number, number format, and others could also be added here. All mentioned options could be changed while running the wizard. The addParameterType() method is used to define number sequence scope. In the example we created a separate sequence for each Dynamics AX company.

Before we start the wizard, we need to initialize number sequence references. This is normally done as a part of the Dynamics AX initialization checklist, but in this example we have to execute it manually by calling the loadAll() method of the NumberSeqApplicationModule class.

Next, we will run the wizard. We will skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.

The newly created number sequence reference appears in the Segment configuration form. Here we can see that the Data area checkbox is checked, meaning that we will have separate number lists for each company. The number sequence setup can normally be located in the module parameter forms.

See also

See Chapter 3, Working with Data in Forms:

Using a number sequence handler