Creating Custom Number Seq:
Hello Friends,
Today I am going to describe how to create a number sequence in AX2012/D365 F and O.We will Take an EDT name as "PJ_Sequence" and create it in the number sequence. For that first, we should create a module for a new number sequence for example "PJModel".
Let's Start,
Step 1:
Create a “Parameter Table” (Ex-PJParameter)
1) Create a "Key" field in that table.
· Key must be Integer Type.
· Set “AllowEditOnCreate” Property to No.
· Set “AllowEdit” Property to No.
· Set “Visible” property to No.
· Set “ExtendedDataType” Property to “ParametersKey”.
2) Create an "Index" for the "Key" field.
· Set “Name” Property to Key.
· Set “AllowDuplicates” to No.
· Set “AlternateKey” to Yes.
Now create several methods in the "PJParameter" table. (Like -Delete, Update, exist, and Find)
public void delete(){super();throw error("@SYS23721");}
public void update(){super();flush PJ_Parameter;}
public static PJ_Parameter find(boolean _forupdate = false){PJ_Parameter parameter;parameter.selectForUpdate(_forupdate);select firstonly parameterindex Keywhere parameter.Key == 0;if (!parameter && !parameter.isTmp()){Company::createParameter(parameter);}return parameter;}
public static boolean Exist(){return (select firstonly RecId from PJ_Parameter).RecId != 0;}
1. Create an Extension of the “NumberSeqModule” base enum and add New Element there For Ex PJ_Seq.
Create an Extension of the “ModuleAxapta” base enum and add New Element there For Ex PJModel.
{
Public NumberSeqModule numberSeqModule()
{
Return NumberSeqModule::PJ_Seq;
}
{
NumberSeqDatatype datatype = NumberSeqDatatype::construct();
/* Work Order Number */
datatype.parmDatatypeId(extendedTypeNum(PJ_Sequence));
datatype.parmReferenceHelp("Unique identifier for work orders");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmSortField(1);
datatype.parmWizardHighest(999999);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
}
[SubscribesTo(classStr(NumberSeqGlobal), delegateStr(NumberSeqGlobal, buildModulesMapDelegate))]
public static void NumberSeqGlobal_buildModulesMapDelegate(Map numberSeqModuleNamesMap)
{
NumberSeqGlobal::addModuleToMap(classnum(NumberSeqModulePJExplain), numberSeqModuleNamesMap);
}
public static NumberSequenceReference numRefPJSequence()
{
NumberSeqScope scope = NumberSeqScopeFactory::createDataAreaScope(curext());
return NumberSeqReference::findReference(extendedtypenum(PJ_Sequence), scope);
}
{
Return NumberSeqModule::PJ_Seq;
}
static client server NumberSequenceReference numRefPJSequence()
{
return NumberSeqReference::findReference(extendedTypeNum(PJ_Sequence));
1.
Create a form for the parameter table (Form Pattern :: Table Of Contents)
Drag the PJParameter and “NumberSequenceReference” Table into the DataSources node of the Form.
[Form]
public class PJ_Parameter extends FormRun
{
boolean runExecuteDirect;
TmpIdRef tmpIdRef;
NumberSeqScope scope;
NumberSeqApplicationModule numberSeqApplicationModule;
container numberSequenceModules;
public void init()
{
this.numberSeqPreInit();
PJ_Parameter::find();
super();
this.numberSeqPostInit();
}
void numberSeqPreInit()
{
runExecuteDirect = false;
numberSequenceModules = [NumberSeqModule::PJ_Seq];
numberSeqApplicationModule = new NumberSeqModulePJExplain();
scope = NumberSeqScopeFactory::createDataAreaScope();
NumberSeqApplicationModule::createReferences(NumberSeqModule::PJ_Seq, scope);
tmpIdRef.setTmpData(NumberSequenceReference::configurationKeyTableMulti(numberSequenceModules));
}
void numberSeqPostInit()
{
numberSequenceReference_ds.object(fieldNum(NumberSequenceReference, AllowSameAs)).visible(numberSeqApplicationModule.sameAsActive());
referenceSameAsLabel.visible(numberSeqApplicationModule.sameAsActive());
}
public NumberSeqModule numberSeqModule()
{
return NumberSeqModule::PJ_Seq;// module literal crated in NumberSeqModule enum extension previously
}
public Common resolveReference(FormReferenceControl _formReferenceControl)
{
NumberSequenceCode code = _formReferenceControl.filterValue(
AbsoluteFieldBinding::construct(fieldStr(NumberSequenceTable, NumberSequence),
tableStr(NumberSequenceTable))).value();
// Do not call super as we’re providing our own disambiguation logic.
// resolvedRecord = super(_formReferenceControl);
return NumberSequenceTable::findByNaturalKey(code, scope.getId(true));
}
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
NumberSequenceTable selectedRecord;
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(NumberSequenceTable), _formReferenceControl, true);
Query lookupQuery;
// Do not call super as we’re providing our own custom lookup logic.
// selectedRecord = super(_formReferenceControl);
// Display the Title and Department fields in the lookup form.
sysTableLookup.addLookupfield(fieldNum(NumberSequenceTable, NumberSequence));
// Create a custom Query that filters on NumberSequenceScope.
lookupQuery = new Query();
lookupQuery.addDataSource(tableNum(NumberSequenceTable)).addRange(fieldNum(NumberSequenceTable, NumberSequenceScope)).value(queryValue(scope.getId(true)));
sysTableLookup.parmQuery(lookupQuery);
// Return the record selected by the user.
selectedRecord = sysTableLookup.performFormLookup();
return selectedRecord;}}
Now Create a “Runnable Class” to Load the LoadModule() Method for Ex NumberSeqLodeJob
class NumberSeqLodeJob
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
NumberSeq PayNumSeq;
PJ_Sequence payid;
ttsbegin;
PayNumSeq = NumberSeq::newGetNum(NumberSeqModulePJExplain::numRefPJSequence());
payid = PayNumSeq.num();
ttscommit;
Info(strFmt("Payslip Id is :%1",payid));
}
1. Now Add this code to that form where you want your number sequence will be generated:[Form]
public class PJDetailsCreate extends FormRun
{
NumberSeqFormHandler numberSeqFormHandler;
NumberSeqFormHandler NumberSeqFormHandler()
{
If (!numberSeqFormHandler)
{
NumberSeqFormHandler = numberseqformhandler::newForm(PJ_Parameter::numRefPJSequence().NumberSequenceId,element,PJTable_ds,fieldNum(PJTable, PJId));
}
return NumberSeqFormHandler;
}
void close()
{
if (NumberSeqFormHandler)
{
numberSeqFormHandler.formMethodClose();
}
super();
}
Now Add Some Method in DataSouece of this Form:
void create(boolean append = false,
boolean extern = false) // If created externally
{
element.numberSeqFormHandler().formMethodDataSourceCreatePre();
super(append);
if (!extern)
{
element.numberSeqFormHandler().formMethodDataSourceCreate(true);
}
}
· Delete =>
public void delete()
{
element.numberSeqFormHandler().formMethodDataSourceDelete();
super();
}
· Write =>
public void write()
{
super();
element.numberSeqFormHandler().formMethodDataSourceWrite();
}
· Validate Write =>
public boolean validateWrite()
{
boolean ret;
ret = super();
ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
if (ret)
{
<TableName>.validateWrite();
}
return ret;
}
· Link Active=>
public void linkActive()
{
;
element.numberSeqFormHandler().formMethodDataSourceLinkActive();
super();
}
Now Time to Set up the number sequence on UI:
1. Now Setup "Number Sequence" just follows these steps;
b) Then Number Sequences > Number Sequences
c) Click on "Number Sequence" in the "New" tab.
d) Fill information in the "Identification" tab.
e) In the "Scope parameters" tab select (Shred/Company)
f) In the "Segments" tab set the length of the number sequence.
g) Now in "General" setup click "continuous" option.
h) Save and generate.
i) Click "close".
Enjoy 👍
}
No comments:
Post a Comment