Shared Number Sequence and Update Time Stamp Table
Muhammad Farzam
Microsoft Dynamics AX || D365 Finance and Operations Technical Consultant || Power Platform
In this article, we have explored the process of creating a custom 'Shared Number Sequence' and updating records in the timestamp table in Dynamics 365 for Finance and Operations.
For generate a number sequence we need to create an EDT String
Associate the EDT 'NumSeqEDT' with the table field where you intend to establish a number sequence
Create NumberSeqApplicationModule Class
public class SharedNumberSequence extends NumberSeqApplicationModule
{
public void loadModule()
{
NumberSeqDatatype datatype = NumberSeqDatatype::construct();
datatype.parmDatatypeId(extendedTypeNum(NumSeqEDT));
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardFetchAheadQty(10);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmSortField(1);
this.create(datatype);
}
static numberSequenceReference numRefNumSeqEDT()
{
return NumberSeqReference::findReference(extendedTypeNum(NumSeqEDT));
}
public NumberSeqModule numberSeqModule()
{
return NumberSeqModule::HRM;
}
[SubscribesTo(classstr(NumberSeqGlobal),delegatestr(NumberSeqGlobal,buildModulesMapDelegate))]
static void buildModulesMapSubsciber(Map numberSeqModuleNamesMap)
{
NumberSeqGlobal::addModuleToMap(classnum(SharedNumberSequence), numberSeqModuleNamesMap);
}
}
After this create a Runnable Class (Job) add the below code
领英推荐
public static void main(Args _args)
{
SharedNumberSequence sharedNumberSequence= new SharedNumberSequence();
sharedNumberSequence.load();
info("Number sequence loaded for NumSeqEDT");
}
Mark this class as "Set As Startup Object"
Navigate to the Organization and Administration -> Number Sequence -> Number Sequence hit Generate Button
After completing this step, a new Shared Number Sequence will be generated. Subsequently, proceed to generate numbers from the sequence. In my scenario, this involves updating records in the TimeStamp table.
select forupdate validtimestate(startDateValue,endDateValue) * from hcmEmployment
where hcmEmployment.Worker == recId;
ttsbegin;
hcmemployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
numSeq = NumberSeq::newGetNum(SharedNumberSequence ::numRefNumSeqEDT());
newnum = numSeq.num();
hcmemployment.NumberSeq= newnum;
hcmemployment.update();
ttscommit;
This constitutes the primary logic wherein the records of the timestamp table are updated, and the generate the new number from the number sequence.