How to create a custom number sequence

 How to create a custom number sequence in Dynamics.


To create a custom number sequence, you need the following:

1. An EDT for the number sequence. EDT is called extended data type, an extension of the primitive data types in Dynamics, which includes: anytype, boolean, date, enum, guid, int, int64, real, str, timeOfDay, utcdatetime.

2. Extended the class for managing number sequences in Dynamics (NumberSeqApplicationModule)

3. Override the class's load module method. This method is protected, which means it can only be accessed by its definition class and subclasses.

4. Specify the specific module you would like the number sequence to be, by returning the specified enum.

5. Subscribe to the build modules map method of the Number Sequence Global class(NumberSeqGlobal).

6. Run the load module as a job class to initialise the number sequence on the parameters module.

7. Run the number sequence wizard to generate the value on the parameters module.


Let's assume we want to create a custom number sequence called Probation Id.


1. Create a Probation Id as an EDT 


2. Create a new class and name it ProbationIdSeq  Extend the NumberSeqApplicationModule class.

public class ProbationIdSeq extends NumberSeqApplicationModule

{}

3. Override the class's load module method.

protected void loadModule()

{

    

   //instantiate the data type of the number sequence and its expected behaviour

NumberSeqDatatype datatype = NumberSeqDatatype::construct();


    datatype.parmDatatypeId(extendedTypeNum(ProbationId));

    datatype.parmReferenceHelp(literalStr("Unique key used for the Probation Id."));

    datatype.parmWizardIsContinuous(false);

    datatype.parmWizardIsManual(NoYes::No);

    datatype.parmWizardFetchAheadQty(10);

    datatype.parmWizardIsChangeDownAllowed(NoYes::No);

    datatype.parmWizardIsChangeUpAllowed(NoYes::No);

    datatype.parmSortField(1);


    datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);

    this.create(datatype);

4. Specify the specific modules for the number sequence. In this case, we will use the Human Resources module.

 public NumberSeqModule numberSeqModule()

 {

     return NumberSeqModule::HRM;

 }

5.  Subscribe to the build modules map method of the Number Sequence Global class(NumberSeqGlobal).

[SubscribesTo(classstr(NumberSeqGlobal),delegatestr(NumberSeqGlobal,buildModulesMapDelegate))]

static void buildModulesMapSubsciber(Map numberSeqModuleNamesMap)

{

    NumberSeqGlobal::addModuleToMap(classnum(ProbationIdSeq), numberSeqModuleNamesMap);

}

6. Run the load module as a job class to initialise the number sequence on the parameters module.

public static void main(Args _args)

{

    Go2FMNPerfProbationIdSeq budgetIdNumSeq = new Go2FMNPerfProbationIdSeq();

        budgetIdNumSeq.load();

    

}

Result:


7. Run the number sequence wizard to generate the value on the parameters module. To get the final result above.

Below are the full code snippets.

1. For custom Number sequence creation

public class ProbationIdSeq extends NumberSeqApplicationModule

{

    protected void loadModule()

    {

        NumberSeqDatatype datatype = NumberSeqDatatype::construct();


        datatype.parmDatatypeId(extendedTypeNum(ProbationId));

        datatype.parmReferenceHelp(literalStr("Unique key used for the Probation Id."));

        datatype.parmWizardIsContinuous(false);

        datatype.parmWizardIsManual(NoYes::No);

        datatype.parmWizardFetchAheadQty(10);

        datatype.parmWizardIsChangeDownAllowed(NoYes::No);

        datatype.parmWizardIsChangeUpAllowed(NoYes::No);

        datatype.parmSortField(1);


        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);

        this.create(datatype);

    }


    public NumberSeqModule numberSeqModule()

    {

        return NumberSeqModule::HRM;

    }


    [SubscribesTo(classstr(NumberSeqGlobal),delegatestr(NumberSeqGlobal,buildModulesMapDelegate))]

    static void buildModulesMapSubsciber(Map numberSeqModuleNamesMap)

    {

        NumberSeqGlobal::addModuleToMap(classnum(ProbationIdSeq), numberSeqModuleNamesMap);

    }


}


2. Job class to run to initialise the number sequence in the module's parameters.

internal final class ProbationLoadId

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu 

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        ProbationIdSeq probationIdNumSeq = new ProbationIdSeq();

            probationIdNumSeq.load();

        

    }


}


Happy coding....




Comments

Popular posts from this blog

Integration Capabilities and Support in Microsoft Dynamics 365 Finance & Operations (F&O) - An Overview

Performance and Monitoring in dynamics 365 F&O.

Dynamics 365 F&O Deployment Architecture: What You Need to Know