Friday, November 12, 2021

create number sequence in d365 x++

 Topic : Create number sequence in d365 using x++.

In this post I created a new number sequence for my existing module. Just follow the below steps.

1. Create a new extension class for NumberSeqModuleMyModule. written the below code in loadModule method.  

         [ExtensionOf(classStr(NumberSeqModuleMyModule))]
    final class NumberSeqModuleMyModule_Extension
    {
        protected void loadModule()
        {
            NumberSeqDatatype datatype = NumberSeqDatatype::construct();

            next loadModule();

            datatype.parmDatatypeId(extendedTypeNum(MyId));
            datatype.parmReferenceHelp(literalStr('My Id'));
            datatype.parmWizardIsContinuous(false);
            datatype.parmWizardIsManual(NoYes::No);
            //datatype.parmWizardFetchAheadQty(10);
            datatype.parmWizardIsChangeDownAllowed(NoYes::No);
            datatype.parmWizardIsChangeUpAllowed(NoYes::No);
            datatype.parmWizardHighest(999999999);
            datatype.parmSortField(1);
            datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
            this.create(datatype);
        }

    }

2. Create a new extension class for parameter table(MyParmeters) and a new method.

    [ExtensionOf(tableStr(MyParameters))] final class MyParameters_Extension { public static NumberSequenceReference myId() { return NumberSeqReference::findReference(extendedTypeNum(MyId)); } }

3. To run the NumberSeq class just create a job(runnable class).

        class RunnableClass

{ public static void main(Args _args) { NumberSeqModuleMyModule loadModule = new NumberSeqModuleMyModule(); ; loadModule.load(); } }

4. run the runnable class and then go to Organization administration –> Number sequences –> Number sequences –> Generate Button (Run the wizard).

5. To test that number seq follow the below code.

    class RunnableClass { public static void main(Args _args) { NumberSeq numberSeq; str num; ; numberSeq = NumberSeq::newGetNum(MyParameter::MyID()); num = numberSeq.num(); info(num); } }

Keep daxing!!

No comments:

Post a Comment