Edit

Schedule sales history data cleanup

As part of its standard operation, Microsoft Dynamics 365 Supply Chain Management generates and stores sales history update data on an ongoing basis. Over time, a large amount of outdated sales history data might accumulate in your system. This accumulated data can cause performance and functional issues when documents that are related to sales orders are posted. (These documents include sales order confirmations, sales packing slips, sales picking lists, and invoices). Therefore, you should set up and schedule the Sales update history cleanup periodic task to run at a regular interval. This task removes all sales history update data that is no longer needed.

If you use the Sales update history cleanup periodic task, enable the Sales history cleanup performance improvements feature, which makes the task run more effectively. (Nevertheless, you can also run the task without enabling this feature.)

Sales history cleanup performance improvements

The Sales update history cleanup periodic batch job can take a long time if it runs infrequently on environments with a high volume of sales updates. In these situations, the Sales history cleanup performance improvements feature can help reduce the run duration and improve reliability.

The feature improves the existing cleanup job in the following ways:

  • It splits the clean-up into batches (you can change the batch size through customizations).
  • It runs for a maximum of two hours (you can change the duration through customizations).
  • Where possible, it leverages database capabilities to minimize locking contention and avoid joining transactional tables during cleanup.

After enabling the feature, the Sales update history cleanup batch job (Sales and marketing > Period tasks > Cleanup > Sales update history cleanup) runs as it did before, but with better performance and for a maximum of two hours. This condition means it might need to run several times to clean up all the data for a specific retention time frame.

This feature must be enabled on your system for you to use it. As of version 10.0.41, this feature is turned on by default. As of Supply Chain Management version 10.0.43, it's mandatory and can't be turned off. If you're running a version older than 10.0.43, admins can turn this functionality on or off by searching for the Sales history cleanup performance improvements feature in the Feature management workspace.

Set up and schedule the Sales history cleanup periodic task

To set up and schedule the Sales history cleanup periodic task, follow these steps:

  1. Analyze your business needs to determine how many days of historic sales order posting data you must keep. Run the cleanup task every three months and a maximum of every six months.

  2. Go to Sales and marketing > Period tasks > Cleanup > Sales update history cleanup.

  3. In the Clean up sales update history dialog box, on the Parameters FastTab, set the following fields:

    • Clean up – Select one of the following values to specify the type of records to clean up:

      • Executed – Delete only records that are fully processed. Because you likely have no further use for these records, this option is the safest.
      • Executed and erroneous – Delete both fully processed records and records where an error occurred. This option is the most commonly used. You might want to inspect and even fix erroneous records instead of having them automatically cleaned up. However, many companies choose to clean up these records too after about a month, because they're probably no longer relevant by that time.
      • All – Delete executed, erroneous, and waiting records. Waiting records are valid but aren't yet fully processed. In most cases, you probably don't want them to be deleted automatically. However, in some situations, you might choose to have them automatically deleted after a specific amount of time has passed.
    • Retain records based on age – Specify whether you want to clean up records based on their age on the day when the task runs or delete records that were created before a fixed date. If you're scheduling the cleanup as a recurring task, set this option to Yes, because the age is always calculated relative to the date when the task runs.

      • Set this option to Yes to enable the Maximum age field. Use this field to specify the maximum age of the records to keep each time that the task runs. The Created until field is ignored.
      • Set this option to No to enable the Created until field. Use this field to specify the oldest creation date of the records to keep when the task runs. The Maximum age field is ignored.
    • Created until – This setting applies only when the Retain records based on age option is set to No. Specify the oldest creation date of the records to keep when the task runs. Records that were created before this date are deleted.

    • Maximum age – This setting applies only when the Retain records based on age option is set to Yes. Specify the maximum age (in days) of the records to keep each time that the task runs. Older records are deleted.

  4. On the Run in the background FastTab, specify how, when, and how often the task runs. Use these settings to implement the schedule that you determined in step 1. The fields work just as they do for other types of batch jobs in Supply Chain Management.

  5. Select OK to apply your settings and close the dialog box.