Book Image

Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition

By : Abhimanyu Singh, Deepak Agarwal
Book Image

Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition

By: Abhimanyu Singh, Deepak Agarwal

Overview of this book

Microsoft Dynamics 365 for Finance and Operations has a lot to offer developers. It allows them to customize and tailor their implementations to meet their organization’s needs. This Development Cookbook will help you manage your company or customer ERP information and operations efficiently. We start off by exploring the concept of data manipulation in Dynamics 365 for Operations. This will also help you build scripts to assist data migration, and show you how to organize data in forms. You will learn how to create custom lookups using Application Object Tree forms and generate them dynamically. We will also show you how you can enhance your application by using advanced form controls, and integrate your system with other external systems. We will help you script and enhance your user interface using UI elements. This book will help you look at application development from a business process perspective, and develop enhanced ERP solutions by learning and implementing the best practices and techniques.
Table of Contents (18 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface

Adding a document handling note


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.

Document handling has a number of configuration parameters that you can find by navigating to Organizationadministration | Setup | Documentmanagement. Please refer to Dynamics 365 for Operations Manuals to find out more.

Dynamics 365 for Finance and Operations also allows you to add document handling notes from the code. This can come in handy when you need to automate the document handling process. In this recipe, we will demonstrate this by adding a note to a vendor account.

Getting ready

Before you start, ensure that document handling is enabled on the user interface. Open Document management parameters by navigating to Organization administration | Setup | Document management and make sure that Use Active document tables is not marked, as shown in the following screenshot:

Then, open the Document types form from the same location and pick or create a new document type with its Group set to Note, as shown in the following screenshot. In our demonstration, we will use Note.

How to do it...

Carry out the following steps in order to complete this recipe:

  1. Navigate to Accountspayable | Vendors | Allvendors and locate any vendor account to be updated, as shown in the following screenshot:
  1. Create a Dynamics 365 for Operations Project, create a new runnable class named VendAccountDocument, and enter the following code snippet. Use the previously selected vendor account and document type:
        class VendAccountDocument 
       { 
         static void main(Args _args) 
        {  
          VendTable vendTable; 
          DocuType  docuType; 
          DocuRef   docuRef; 
 
          vendTable = VendTable::find('1005'); 
          docuType  = DocuType::find('Note'); 
 
          if (!docuType || 
           docuType.TypeGroup != DocuTypeGroup::Note) 
         { 
           throw error("Invalid document type"); 
         } 
 
 
          docuRef.RefCompanyId = vendTable.dataAreaId; 
          docuRef.RefTableId   = vendTable.TableId; 
          docuRef.RefRecId     = vendTable.RecId; 
          docuRef.TypeId       = docuType.TypeId; 
          docuRef.Name         = 'Automatic note'; 
          docuRef.Notes        = 'Added from X++'; 
          docuRef.insert(); 
 
          info("Document note has been added successfully"); 
        } 
 
       } 
  1. Run the class to create the note.
  2. Go back to the vendor list and click on the Attachments button in the form's Action pane or select Document handling from the Command menu under File to view the note added by our code, as shown in the following screenshot:

How it works...

All the document handling notes are stored in the DocuRef table, where three fields, RefCompanyId, RefTableId, and RefRecId, are used to identify the parent record. In this recipe, we set these fields to the vendor company ID, vendor table ID, and vendor account record ID, respectively. Then, we set the type, name, and description and inserted the document handling record. Notice that we have validated the document type before using it. In this way, we added a note to the record.