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
- Microsoft Dynamics AX 2012
- Documents management framework must be activated (File à Tools à Options à General tab à Miscellaneous fast tab à Check the Document handling active checkbox)
- Number sequence for document management must be generated (Organization administration à Setup à Document management à Document management parameters à Number sequences fast tab)
- 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
- At least one document type must be setup (Organization administration à Setup à Document management à Document types)
Important Concepts
-
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.
-
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.
-
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.
-
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
- First of all create a new Form. Open AOT àForms
-
Right click on Forms and create a New Form named DocuMangDemo
- Navigate to the Design node of the form and add a StringEdit control
- Name the control as FileName and set its ExtendedDataType property to FilenameOpen and AutoDeclaration property to Yes
- Similarly, add another StingEdit control and name it as DocuType. Also, set its ExtendedDataType property to DocuTypeId and AutoDeclaration property to Yes
- Add another StingEdit control, and name it as CustAccount. Set its ExtendedDataType property to CustAccount and AutoDeclaration property to Yes
- Add a new Button and name it as SaveDoc. Set its Text property as Save and Left property to Auto (right)
- Add a new Button and name it as Open. Set its Text property as Open and Left property to Auto (right)
- The final design should resemble that shown below:
- 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
-
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:
|
str filenameLookupTitle()
{
return "Select file to save";
}
|
-
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:
|
str filenameLookupInitialPath()
{
return "";
}
|
-
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:
|
FilenameFilter filenameLookupFilter()
{
#File
return [#AllFilesType, #AllFilesName+#AllFilesExt];
}
|
-
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:
|
str filenameLookupFileName()
{
return "";
}
|
-
On the class declaration of the form, write the following code:
-
Override the clicked method of the button SaveDoc and write the following code in it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
void clicked()
{
DocuActionArchive docuActionArchive;
CustTable custTable;
super();
try
{
ttsBegin;
//find the selected customer record
custTable = CustTable::find(CustAccount.valueStr());
//Create DocuRef table record and set required values
docuRef.initValue();
docuRef.RefTableId = custTable.TableId;//TableId, for which the document should be attached.
docuRef.RefRecId = custTable.RecId;//RecId, for which the document should be attached.
docuRef.RefCompanyId = custTable.dataAreaId; //CompanyId, for which the document should be attached.
docuRef.TypeId = DocuType.valueStr(); // The type of document
docuRef.insert();
//To stores the file to document archive
docuRef.selectForUpdate(true);
docuActionArchive = new DocuActionArchive();
docuActionArchive.setDocuType(docuRef.TypeId);
docuActionArchive.add(docuRef, FileName.valueStr());
ttscommit;
info("Document successfully attached");
}
catch
{
error("Document attachment failed");
}
}
|
-
Override the clicked method of the button Open and write the following code in it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
void clicked()
{
//creating action class object based on document type
DocuRef docuRefLocal=DocuRef::findRecId(DocuRef.RecId);
DocuAction docuActionLocal=DocuAction::newDocuType(docuRefLocal.docuType());
//create args object
Args args=new Args();
args.record(docuRefLocal);
args.parmEnumType(enumNum(DocuCode));
args.parmEnum(DocuCode::Open);
//run the action class to open the document
docuActionLocal.findDocuTable(docuRefLocal.RefTableId);
docuActionLocal.run(args);
super();
}
|
- The document management framework is implemented. To test it, run the form
- Select any file, document type and customer in File name, Type and Customer account fields respectively
- To save the file, click the Save button. An info log will be shown upon a successful save
- To open the saved file, click on Open button. The file saved in the previous step will be opened
All of these tips are great, that’s very interesting. I’m so tempted to try that myself, but you would think if it were effective, more people would do it.
ReplyDeleteDocument Management Software India
Document Management Software Chennai
Document Management Software
Electronic Document Management System