It is a good practice to add some kind of note to the record when doing data renaming, merging, or any other data manipulation task, whether it's manual or automatic. Dynamics AX allows adding a note or a file to any records by using the so called Document handling feature.
By default, it is enabled for all tables, but can be restricted to fewer tables by changing its configuration parameters.
Document handling can be accessed from the form toolbar by selecting the Document handling icon or choosing Document handling from the Command menu. A form appears, which allows adding notes or files to any currently selected record.
Dynamics AX also allows us to add document handling notes from the code, which helps developers or consultants to add additional information when doing various data migration or conversion tasks.
In this recipe, we will add a note to vendor account 5001.
Open AOT and create a new job called VendAccountDocu, and enter the following code:
static void VendAccountDocu(Args _args) { DocuRef docuRef; #define.vend('5001') #define.docuType('Note') ; docuRef.RefCompanyId = curext(); docuRef.RefTableId = tablenum(VendTable); docuRef.RefRecId = VendTable::find(#vend).RecId; docuRef.TypeId = #docuType; docuRef.Name = 'Imported'; docuRef.Notes = 'This vendor was imported.'; docuRef.insert(); }
Run the job to create the note.
Open Accounts payable | Vendor Details, and locate the vendor account:
Click the Document handling button on the form toolbar or select Document handling from the Command menu to view the note added by our code:
All document handling notes are stored in the DocuRef table, where three fields, RefCompanyId, RefTableId, and RefRecId are used to identify the parent record. In our recipe, we set those fields to the current company account, vendor table ID, and vendor account record ID respectively.
Next, we set note type, name, and description and insert the document handling record. In this way, we added a note to the record. The code in this recipe could be also added to a separate method for further reuse.