Monday, November 14, 2022

D365 F&O Create a new number sequence Using X++ for custom table

 

D365 F&O Create a new number sequence Using X++ for custom table


Purpose of creating a new number sequence

number sequence is to be used as a unique identifier, readable alphanumeric number for Master data

To start identify the field on a table should use a number sequence, as an example, we will use that ID field in SF_Table .



You must use a string field that has an Extended Data Type. In this example, the EDT is named TransactionID



In Visual Studio Synchronize database to create the table on your database



in Visual Studio create a new class that extends NumberSeqApplicationModule to add a row to the ‘Number sequence’ tab on a parameters form.  number sequence reference allows the user to specify which number sequence code should be used for that field.

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

    static void buildModulesMapSubsciber(Map numberSeqModuleNamesMap)

    {

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

    }

 

add the following method and code. It is used to add your EDT to the list of number sequence references.



I will add this Number sequence to Accounts Payable Module

Please go to NumberSeqModule enum to check the module value  , I will add code that uses the (Vend) on my case

 




 public NumberSeqModule numberSeqModule()

    {

        return NumberSeqModule::Vend;

    }

I have to create a new number sequence for the Vend module If you want to create a number sequence for another module you should extend another class (Ex NumberSeqModule_ModuleName) or if you want to create a number sequence for a new module first you should add the new module at NumberSeqModule base enum.


  public NumberSeqModule numberSeqModule()
    {
        return NumberSeqModule::Vend;
    }

 

 

Add the loadModule method following the example below.

parameter values can also be changed based on your needs. code shows the most common values.


    protected void loadModule()

    {

        NumberSeqDatatype datatype = NumberSeqDatatype::construct();

 

        datatype.parmDatatypeId(extendedTypeNum(TransactionID));

        datatype.parmReferenceHelp(literalStr("Unique key for Transaction 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);

    }

To create a record in the ‘Number sequence’ tab of the parameters form in the Accounts Payable module we need to Create Runnable Class (Job)


   public static void main(Args _args)

    {

        SFIdNumSeq sFIdNumSeq = new SFIdNumSeq();

        sFIdNumSeq.load();

        info("finished");

    }

load method exists on the base class, and will call the loadModule method on child class.

In Visual Studio project to run Runnable class set as startup object




After running Runnable class, go the parameters form you added the number sequence reference to.

Go to the ‘Number sequence’ tab and check new row. Without Number sequence code


Go to Organization Administration >> Number sequence



Click Generate


Click Next in wizard



Finally, on ‘Completed’ page, and click ‘Finish’.



Filter Account Payable on Area & Reference created in parameter form


You can edit Number sequence segment


Go to number sequence list page, set the system generated ‘Acco_11156 ‘ for the company 

 

Go to Form data source >> Override Create Method




 

public void create(boolean _append = false)

        {

            TransactionID transID;

            NumberSequenceReference numberSequenceReference;

 

            super(_append);

 

            numberSequenceReference = NumberSeqReference::findReference(extendedTypeNum(TransactionID));

            if (numberSequenceReference)

            {

                transID = NumberSeq::newGetNum(numberSequenceReference).num();

                SF_Table.ID = transID;

            }

        }

Replace TransactionID with the name of your EDT.

 

Go to you form & Create new Record

New number sequence will be generated automatically



 

No comments:

Post a Comment