Book Image

Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition

By : Abhimanyu Singh, Deepak Agarwal
Book Image

Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition

By: Abhimanyu Singh, Deepak Agarwal

Overview of this book

Microsoft Dynamics 365 for Finance and Operations has a lot to offer developers. It allows them to customize and tailor their implementations to meet their organization’s needs. This Development Cookbook will help you manage your company or customer ERP information and operations efficiently. We start off by exploring the concept of data manipulation in Dynamics 365 for Operations. This will also help you build scripts to assist data migration, and show you how to organize data in forms. You will learn how to create custom lookups using Application Object Tree forms and generate them dynamically. We will also show you how you can enhance your application by using advanced form controls, and integrate your system with other external systems. We will help you script and enhance your user interface using UI elements. This book will help you look at application development from a business process perspective, and develop enhanced ERP solutions by learning and implementing the best practices and techniques.
Table of Contents (18 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface

Enhancing the data consistency checks


It is highly recommended that you run the standard Dynamics 365 for Finance and Operations data consistency checks from time to time, which can be found by navigating to System administration | Periodic tasks | 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 be easily extended.

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

Getting ready

Before we start, we need to create an invalid setup in order to make sure that we can simulate data inconsistency. Navigate to Fixed assets | Setup | Value models and create a new model, for instance, TEST, as shown in the following screenshot:

Navigate to 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, as shown here:

Go back to the Value models form and delete the previously created value model. Now, we have a nonexistent value model in the fixed asset posting settings.

How to do it...

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

  1. In the Dynamics 365 Project, create a new class named AssetConsistencyCheck with the following code snippet:
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)); 
    } 
 
} 
  1. Navigate to System administration | Periodic tasks | Database | Consistency check, select the newly created Fixed assets option from the Module drop-down list, and click on OK to run the check, as shown here:
  1. Now, the message displayed in the Infolog window should complain about the missing value model in the fixed assets posting settings, as shown in the following screenshot:

How it works...

The consistency check in Dynamics 365 for Finance and Operations 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 validating 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(): This provides a name to the consistency check form.
  • helpText(): This displays some explanation about the check.
  • executionOrder(): This determines where the check is located in the list.
  • run(): This holds the code to perform the actual checking. Here, we use the kernelCheckTable() member method, which validates the given table.

There's more...

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

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