Applying Document Management Framework in Microsoft Dynamics AX 2012

Overview

Document management provides the capability to store documents in a system. The document management framework in Microsoft Dynamics AX is used to attach documents of any type to entity records of any type.

Pre-requisites

  1. Microsoft Dynamics AX 2012
  2. Documents management framework must be activated (File à Tools à Options à General tab à Miscellaneous fast tab à Check the Document handling active checkbox)
  3. Number sequence for document management must be generated (Organization administration à Setup à Document management à Document management parameters à Number sequences fast tab)
  4. Required file types must be enabled (Organization administration à Setup à Document management à Document management parameters à File types fast tab). Only the file types added here can be stored in Dynamics AX
  5. At least one document type must be setup (Organization administration à Setup à Document management à Document types)

Important Concepts

  1. Document Type

    Document type defines the type of document that will be stored in Microsoft Dynamics AX. It also defines the location where the document will be stored. Apart from it, different type of document management parameters can also be setup using document types.

    To store document using document management framework, document types must be defined. Dynamics AX by default contains multiple types of document like File, Notes, and URL.

  2. DocuRef Table

    DocuRef table holds the relationship between the document and the record to which a document is attached. It stores records details like Record Id, Table Id and Company Id, as well as the type of document.

  3. DocuValue Table

    DocuValue table holds the actual document in case the document is stored in a database. Otherwise it stores the path where the document is saved.

  4. DocuActionArchive Class

    DocuActionArchive class is used to store the document in Dynamics AX. It creates a record in DocuValue table as well as physically storing the document. Its main tasks are as follows:

  • Opens the file selection dialog if file is not specified
  • Generates a number sequence for the document
  • Checks the location of where to save the document (i.e. Database or File system)
  • Stores the document and creates and update records in DocuValue and DocuRef tables respectively

Scenario

As part of this tutorial, a document of any type can be attached to a customer record.

Steps

  1. First of all create a new Form. Open AOT àForms
  2. Right click on Forms and create a New Form named DocuMangDemo

     

  3. Navigate to the Design node of the form and add a StringEdit control
  4.  

  5. Name the control as FileName and set its ExtendedDataType property to FilenameOpen and AutoDeclaration property to Yes
  6. Similarly, add another StingEdit control and name it as DocuType. Also, set its ExtendedDataType property to DocuTypeId and AutoDeclaration property to Yes
  7. Add another StingEdit control, and name it as CustAccount. Set its ExtendedDataType property to CustAccount and AutoDeclaration property to Yes
  8. Add a new Button and name it as SaveDoc. Set its Text property as Save and Left property to Auto (right)
  9. Add a new Button and name it as Open. Set its Text property as Open and Left property to Auto (right)
  10. The final design should resemble that shown below:
  11.  

  12. Now, to open the file selection dialog, add the following methods on the form. These methods are needed in order for FilenameOpen EDT to work
  13. Add a new method and name it filenameLookupTitle. This method will return the title of the file selection dialog. Write the following code in the method:
  14. Add a new method and name it filenameLookupInitialPath. This method will open the dialog with an initial path. Write the following code in the method:

  15. Add a new method and name it filenameLookupFilter. This method will set the file filters for the dialog. Write the following code in the method:

  16. Add a new method and name it filenameLookupFileName. This method will be used to set the default value of the file field on the dialog. Write the following code in the method:

  17. On the class declaration of the form, write the following code:

  18. Override the clicked method of the button SaveDoc and write the following code in it:

  19. Override the clicked method of the button Open and write the following code in it:

  20. The document management framework is implemented. To test it, run the form
  21. Select any file, document type and customer in File name, Type and Customer account fields respectively
  22.  

  23. To save the file, click the Save button. An info log will be shown upon a successful save
  24.  

  25. To open the saved file, click on Open button. The file saved in the previous step will be opened
  26.  

  • Wouldn’t you just use the standard document management form that is native to AX??? And isn’t that a much better solution?