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.
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.
Carry out the following steps in order to complete this recipe:
- 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)); } }
- Navigate to
System administration
|Periodic tasks
|Database
|Consistency check
, select the newly createdFixed assets
option from theModule
drop-down list, and click onOK
to run the check, as shown here:
- 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:
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 thekernelCheckTable()
member method, which validates the given table.
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(); }