Tuesday, October 27, 2015

CostSheetCache table is too large. How to clear it out


The CostSheetCache table which is used as a temp location for cost sheets to help generate prices is not cleared automatically in AX unless you tell it to. So it can become very large inside of your DB (sometimes 10-30GB+) There are two ways you can clear out this information properly to keep this table small in size.

1.) Manually trigger the clearing inside of AX (this is the only way I know how to do it via default AX)
Go to  Production Control / Setup / Routes / Cost Groups​  Modify any record on this form and it will trigger the cleanup whenever you close the form.

2.) Create a job with the following code.

static void CostSheetCacheClear(Args _args)
{
    //this will clear the table CostSheetCache
    CostSheetFactory::construct().clearCachedData();
    info("Cleared the table CostSheetCache");
}

This is the same code that gets triggered in step 1 and can be found on

\Tables\BOMCostGroup\insert(), update(), delete()

3 comments:

  1. Dear Adam, for your script what kind of job , TSQL or activeX script.
    and if we running this script is there no impact with costing data

    ReplyDelete
  2. The example listed above is a job within the AOT. However we found that once this table was 20+GB it took forever to run.

    So we started to make it a maintenance task during code deployments to clear the table via SQL (as a truncate table sql command which is a lot faster and does the same thing) then restart the aos.

    ReplyDelete
  3. Dear Adam,

    Thank you...!!

    My Problem was solved....!!

    ReplyDelete