Book Image

Microsoft Dynamics AX 2012 Development Cookbook

By : Mindaugas Pocius
Book Image

Microsoft Dynamics AX 2012 Development Cookbook

By: Mindaugas Pocius

Overview of this book

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.
Table of Contents (15 chapters)
Microsoft Dynamics AX 2012 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Enhancing the data consistency check


It is highly recommended to run the standard Dynamics AX data consistency check from time to time, that is located in System administration | Periodic | Database | Consistency check, to check the system's data integrity. This function finds orphan data, validates parameters, and does many other things, but it does not do everything. The good thing is that it can easily be extended to match different scenarios.

In this recipe, we will see how we can enhance the standard Dynamics AX consistency check to include more tables in its data integrity validation.

Getting ready

Before we start, we need to create an invalid setup to make sure we can simulate data inconsistency. Open Fixed assets | Setup | Value models and create a new model, for instance, TEST:

Open Fixed assets | Setup | Fixed asset posting profiles and under the Ledger accounts group, create a new record with the newly created value model for any of the posting types:

Go back to the Value models form, and delete the previously created value model.

Now, we have a non-existing value model in the fixed asset posting settings.

How to do it...

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

  1. 1. In the AOT, create a new class AssetConsistencyCheck with the following code:

    class AssetConsistencyCheck extends SysConsistencyCheck
    {
    }
    client server static ClassDescription description()
    {
    return "Fixed assets";
    }
    client server static HelpTxt helpText()
    {
    return "Consistency check of the fixed asset module";
    }
    public Integer executionOrder()
    {
    return 1;
    }
    public void run()
    {
    this.kernelCheckTable(tableNum(AssetLedgerAccounts));
    }
    
  2. 2. Open System administration | Periodic | Database | Consistency check, select the newly created Fixed assets option in the Module drop-down, and click OK to run the check:

  3. 3. Now the message displayed in the Infolog should complain about the missing value model in the fixed asset posing settings:

How it works...

The consistency check in Dynamics AX validates only the predefined list of tables for each module. The system contains a number of classes derived from SysConsistencyCheck. For example, the CustConsistencyCheck class is responsible for validating the Accounts receivable module, LedgerConsistencyCheck —for General ledger, and so on.

In this recipe, we created a new class named AssetConsistencyCheck, extending the SysConsistencyCheck class for the fixed asset module. The following methods were created:

  • description() provides a name on the consistency check form.

  • helpText() displays some explanation about the check.

  • executionOrder() determines where in the list the check is located.

  • run() holds the code to perform actual checking. Here we use the kernelCheckTable() member method, which validates the given table.

There's more...

The classes we just mentioned can only be executed from the main Consistency check form. Individual checks could also be invoked as stand-alone functions. We just need to create an additional method to allow running of the class:

static void main(Args args)
{
SysConsistencyCheckJob consistencyCheckJob;
AssetConsistencyCheck assetConsistencyCheck;
consistencyCheckJob = new SysConsistencyCheckJob(
classidget(assetConsistencyCheck));
if (!consistencyCheckJob.prompt())
{
return;
}
consistencyCheckJob.run();
}