Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Dynamics AX 2012 Development Cookbook

You're reading from   Microsoft Dynamics AX 2012 Development Cookbook Customizing Dynamics AX to suit the specific needs of an organization is plain sailing when you use this cookbook of modifications. With more than 80 practical recipes it's the perfect handbook for all Dynamics AX developers.

Arrow left icon
Product type Paperback
Published in May 2012
Publisher Packt
ISBN-13 9781849684644
Length 372 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mindaugas Pocius Mindaugas Pocius
Author Profile Icon Mindaugas Pocius
Mindaugas Pocius
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Microsoft Dynamics AX 2012 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
1. Preface
1. Processing Data FREE CHAPTER 2. Working with Forms 3. Working with Data in Forms 4. Building Lookups 5. Processing Business Tasks 6. Integration with Microsoft Office 7. Using Services 8. Improving Development Efficiency 9. Improving Dynamics AX Performance

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();
}
You have been reading a chapter from
Microsoft Dynamics AX 2012 Development Cookbook
Published in: May 2012
Publisher: Packt
ISBN-13: 9781849684644
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image