Search code examples
axaptadynamics-ax-2009

Cleaning up unused Customers


I am being asked to clean unused Customers in our AX database. The challenge is defining "unused" of course.

Is there any diagram anywhere documenting the table's relationship in Dynamics AX 2009 ?

For example, I see the table LedgerJournalTrans has the "AccountNum" field. I guess I could extrapolate that if a Customer has no associated records in LedgerJournalTrans, it is unused but I think it may be a bit more complicated than this.

Anything else I should watch for ?

Thanks!


Solution

  • I have had to do this before, and it really isn't terribly challenging, you just have to do your due diligence. I wouldn't feel as confident with ian_scho's method because it only checks two tables, but I'd say his method gets the 80%.

    I would say your best method is to copy the class Classes\InventUnusedDimCleanUp and modify the simple functions in the \run method.

    This is a base class that basically does the following, except I'm going to substitute InventDimId with AccountNum for solidarity:

    • Insert every customer account (AccountNum) into an empty check table as a starting reference
    • Traverse the Data Dictionary\Tables tree node over every table in the AOT
    • While traversing, determine if the table is a candidate table to compare against
    • If it is a candidate table, then traverse each field and determine if it's a candidate field by checking if it is an EDT of CustAccount or an EDT that extends it
    • If we determine it is a candidate field, then insert that into our container list of [TableId,FieldId]s
    • Next, loop through the container and for each tableId/fieldId, delete from our check table AccountNum's that DO exist in the candidate tables, so that we will be left with a check table of AccountNum's that were not found in any table
    • Lastly, a step you will probably do manually, but it will delete from CustTable the customers that are remaining in the check table, which have been deemed unused

    This should accomplish your task, but doesn't take in account any external systems or customization you may have...but it gets the 95%.