Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Dynamics 365 for Finance and Operations Development Cookbook

You're reading from   Dynamics 365 for Finance and Operations Development Cookbook Recipes to explore forms, look-ups and different integrations like Power BI and MS Office for your business solutions

Arrow left icon
Product type Paperback
Published in Aug 2017
Publisher Packt
ISBN-13 9781786468864
Length 480 pages
Edition 4th Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Deepak Agarwal Deepak Agarwal
Author Profile Icon Deepak Agarwal
Deepak Agarwal
Abhimanyu Singh Abhimanyu Singh
Author Profile Icon Abhimanyu Singh
Abhimanyu Singh
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Processing Data FREE CHAPTER 2. Working with Forms 3. Working with Data in Forms 4. Building Lookups 5. Processing Business Tasks 6. Data Management 7. Integration with Microsoft Office 8. Integration with Power BI 9. Integration with Services 10. Improving Development Efficiency and Performance

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); } }
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
You have been reading a chapter from
Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition
Published in: Aug 2017
Publisher: Packt
ISBN-13: 9781786468864
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image