Document handling in Dynamics 365 for Finance and Operations is a feature that allows you to add notes, links, documents, images, files, and other related information to almost any record in the system. For example, we can track all the correspondence sent out to our customers by attaching the documents to their records in Dynamics 365 for Finance and Operations. Document handling on most of the forms can be accessed either from the Action pane by clicking on the Attachments button and selecting Document handling from the Command menu under File or selecting the Document handling icon from the status bar.Lets create an attachment using X++ and attach a note to a customer record. Lets move over to visual studio.
Step 1.
If you haven't created a project. Create a new Visual Studio Project, the type should be Unified Operations. In the new D365 Visual Studio project lets add a new class for managing documents. Select the project name in the solution and right Click.
Step 2.In the dialog which pops up we have a number of choices to add to the project. In the left hand pane select Code. This will narrow our choices to code items. In the items remaining in the list select the typed a runnable class. Give it a Name
I've given the class the name. RunnableClassCustomerDocument. In the code pane past the following code.
8 Let's go over to the Customer Listing pages in Dynamics 365. Lets select a customer in this case I'm selecting Account Number 004007 and Name Owen Tolley. In the Customer menu select the attachments option to see what documents exist
9 In the attachment page , there are no attachments. So lets go back to visual studio and run our code
10 Don't forget to copy the customer number for our code 004007
11 In the code page lets paste 004007 as the customer we are going to add the attachment for. In the code we are going to search for the customer 004007. We then return the customer object we are going to attach the document for. Next we search for the
12 document Type "Note". The next lines we add fields like Name of the attachment and the notes. We also set the type of the document we are adding. Before we run the code, right click the new class name and set to StartUp Object
13 Click Start Without Debugging. i tend to use this option for speed purposes. If you want to trace the code line by line choose the start debugging option
14 Once the code has been compiled and built the following window is display. Review the message at the top of the screen is matches the message box from our code. Document note has been added successfully. Lets review our customer record.
15 Navigate to the customers list in Dynamics. Find the customer we reviewed earlier in the article and click the attachments menu option as we did previously.
16 In the attachment screen we now see a Note entry. We can also see that the note comments and when the note was added.
17 This is really useful piece of functionality. There are lots of scenario's where you will need to store documents against records in Dynamics . Hope it was useful. Thats the ends of the tutorial.
X++ Code
class RunnableClassCustomerDocument
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
CustTable custTable;
DocuType docuType;
DocuRef docuRef;
custTable = CustTable::find('004007');
docuType = DocuType::find('Note');
if (!docuType || docuType.TypeGroup != DocuTypeGroup::Note)
{
throw error("Invalid document type");
}
docuRef.RefCompanyId = custTable.dataAreaId;
docuRef.RefTableId = custTable.TableId;
docuRef.RefRecId = custTable.RecId;
docuRef.TypeId = docuType.TypeId;
docuRef.Name = 'Automatic note';
docuRef.Notes = 'Added from X++';
docuRef.insert();
info("Document note has been added successfully");
}
}