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

Creating a new number sequence


Number sequences in Dynamics 365 for Finance and Operations are used to generate specifically formatted numbers for record identification. These number sequences can be anything from voucher numbers or transaction identification numbers to customer or vendor accounts.

When developing custom functionality, often one of the tasks is to add a new number sequence to the system in order to support newly created tables. Adding a number sequence to the system is a two-step process. First, we create the number sequence itself; second, we start using it in some particular form or from the code.

D365 contains a list of NumberSeqApplicationModule derivative classes, which hold the number sequence's setup data for the specific module. These classes are read by the number sequence wizard, which detects existing number sequences and proposes to create the missing ones or newly added ones. The wizard is normally run as a part of the application initialization. It can also be rerun any time later when expanding the D365 functionality used, where a setup of additional number sequences is required. The wizard also has to be rerun if new custom number sequences are added to the system.

In this recipe, we will do the first step, that is, add a new number sequence to the system. In a standard application, the customer group number is not driven by any number sequence, so we will enhance this by creating it. The second step is explained later in the Using a number sequence handler recipe in Chapter 3, Working with Data in Forms.

How to do it...

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

  1. Create a new NumberSeqModuleCustomer_packt class in the D365 Project that extends the NumberSeqModuleCustomer class in the Application and add the following code snippet at the bottom of the loadModule_Extension() method:
        class NumberSeqModuleCustomer_packt extends   
         NumberSeqModuleCustomer 
       {  
         public void loadModule_Extension() 
        { 
          NumberSeqDatatype datatype = NumberSeqDatatype::construct(); 
 
          datatype.parmDatatypeId(extendedTypeNum(CustGroupId)); 
          datatype.parmReferenceHelp("Customer group ID"); 
          datatype.parmWizardIsContinuous(false); 
          datatype.parmWizardIsManual(NoYes::No); 
          datatype.parmWizardIsChangeDownAllowed(NoYes::Yes); 
          datatype.parmWizardIsChangeUpAllowed(NoYes::Yes); 
          datatype.parmWizardHighest(999); 
          datatype.parmSortField(20); 
          datatype.addParameterType( 
          NumberSeqParameterType::DataArea, true, false); 
 
          this.create(datatype); 
        } 
       }  

Note

Downloading the example code You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you.

  1. Create a new runnable class (Job) with the following lines of code, build the solution and run it:
         class loadNumSeqCustPackt
        {   
          /// <summary> 
          /// Runs the class with the specified arguments. 
          /// </summary> 
          /// <param name = "_args">The specified arguments.</param> 
           public static void Main(Args args) 
          {  
            //define the class variable 
            NumberSeqModuleCustomer_packt nymberSeqMod = new  
             NumberSeqModuleCustomer_packt(); 
 
            //load the number sequences 
             nymberSeqMod.loadModule_Extension(); 
          } 
 
        } 
  1. Run the number sequence wizard by clicking on the Generate button under Number sequence by going to Organization administration | Common | Number sequence and then click on the Next button, as shown in the following screenshot:
  1. Click on Details to view more information. Delete everything apart from the rows where Area is Accounts receivable and Reference is Customer group. Note the number sequence codes and click on the Next button, as shown here:
  1. On the last page, click on the Finish button to complete the setup, as shown in the following screenshot:
  1. The newly created number sequences now can be found in the Number sequence form, as shown in the following screenshot:
  1. Navigate to Organization administration | Number sequences | Segment configuration and notice the new Customer group reference under the Accounts receivable area:
  1. Navigate to Accounts receivable | Setup | Accounts receivable parameters and select the Number sequences tab. Here, you should see the new number sequence code:
  1. The last thing to be done is to create a helper method for this number sequence. Create a new extension class CustParameters_Extension for the CustParameters table and add it to the Dynamics 365 Project and then create the following method and build the solution:
        [ExtensionOf(tableStr(CustParameters))] 
        final  class CustParameters_Extension 
        { 
          /// <summary> 
          /// Gets the number reference customer group id. 
          /// </summary> 
          /// <returns> 
          /// An instance of the <c>NumberSequenceReference</c> class. 
          /// </returns> 
          client server static NumberSequenceReference  
           numRefCustGroupId() 
          {  
            NumberSequenceReference NumberSeqReference; 
          
            NumberSeqReference = NumberSeqReference::findReference
            (extendedTypeNum(CustGroupId)); 
             return NumberSeqReference; 
          } 
        } 

How it works...

We start the recipe by adding a number sequence initialization code into the NumberSeqModuleCustomer_packt class. As understood from its name, the number sequence initialization code holds the initialization of the number sequences that belong to the Accounts receivable module.

The code in the loadModule_Extension() method defines the default number sequence settings to be used in the wizard, such as the data type, description, and highest possible number. Additional options such as the starting sequence number, number format, and others can also be added here. All the mentioned options can be changed while running the wizard. The addParameterType() method is used to define the number sequence scope. In the example, we created a separate sequence for each Legal entity.

Before we start the wizard, we initialize number sequence references. This should be done as a part of the Dynamics 365 for Finance and Operations initialization checklist, but in this example, we execute it manually by calling the loadModule_Extension() method of the NumberSeqApplicationModule_packt class.

Next, we execute the wizard that will create the number sequences for us. We skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.

The newly created number sequence reference appears in the Segment configuration form. Here, we can see that the Data area checkbox is checked, which means that we will have separate number lists for each company. The number sequence setup can be normally located in the module parameter forms.

See also

  • The Using a number sequence handler recipe in Chapter 3, Working with Data in Forms