Document References Are Not Always Deleted

In Dynamics AX it’s possible to add in document reference in many forms using the document handling functionality. However, when you sometimes delete a record that has an associated document reference; this reference in the DocuRef table remains. This is due to the fact that there is not always a relation between a table and DocuRef. Therefore if you run the consistency check report, you may find that you see lots of missing references found as the parent table record no longer exist.

One example of this is the ProdTable, for production orders. In order to make this function so that whenever you delete a record, it deletes the associated document reference follow these steps below (this example if for ProdTable, but just follow the same process for your required tables): 

  • From the AOT expand to Data Dictionary > Tables > DocuRef > Relations
  • Add in a new relation – call it ProdTable
  • Set the properties on this relation to point to the ProdTable
  • Add in the following 3 relations (all relation type Normal)
    • DocuRef.RefRecId == ProdTable.RecId
    • DocuRef.RefRecTableId == ProdTable.TableId
    • DocuRef.RefCompanyId == ProdTable.dataAreaId
  • Save the DocuRef table.


  • Next go to  AOT > Data Dictionary > Tables > ProdTable > DeleteActions
  • Add in a new Delete Action, set the properties to be:
    • Table: DocuRef
    • DeleteAction: Cascade



  • Save the changes.
  • Now when you run the consistency check you will not get any errors on ProdTable for new notes added. You may still see old records as these need to be manually cleaned.

 Note: Please make sure that you have backups of application files and data before making changes.

author: Thomas Treen
editor: Thomas Treen
date: 18/Feb/2011

Comments (1)

  1. Boye Walters says:

    To check which records are no longer used, you can use this job:

    static void JobCheckDocuRef(Args _args)


    Common common;

    DictTable dictTable;

    Docuref     docuref;


    While select docuref


       dictTable = new DictTable(docuref.RefTableId);

       common = dictTable.makeRecord();

       select firstOnly common where common.RecId == docuref.RefRecId;



           warning(strfmt("refTableid %1 refRecId: %2", tableid2name(docuref.RefTableId), docuref.RefRecId));




Skip to main content