Saturday, October 31, 2015

AX 2012: Create new module

How to Create new module in ax 2012

======================================================================
New Module:

1-  create a "Parameter" table in "Table" node of AOT (Like – “OfcAdminParameters”).

2- Create "Key" field in that table.

3- Create "Index" for "Key" field.

4- Create several methods in "Methods" node of "Parameter" table in AOT. (Like - Delete, Update, exist, and Find, NumberSeqModule)
************************************************************************************
Methods –on Parameter table level
Delete:
Void delete ()
{
Throw error ("@SYS23721");
}
Update:
Void update ()
{
Super ();
//just write flush Parameter table name
Flush OfcAdminParameters;
}
Exist:
Static Boolean exist ()
{
Return (select firstonlyRecId from OfcAdminParameters).RecId != 0;
}
Find:
//AOSRunMode::CalledFrom
Static OfcAdminParameters find (Boolean _forupdate = false)
{
OfcAdminParameters parameter;

parameter.selectForUpdate(_forupdate);

Select firstonlyparameter Index Key     Where parameter.Key == 0;
If (!parameter&& !parameter.isTmp())
{
Company::createParameter(parameter);
}
Return parameter;
}

NumberSeqModule:-
Static client server NumberSeqModulenumberSeqModule ()
{
Return NumberSeqModule::OfcMgmt;
}

// If you want to create another module then -
5- Now, add an element to "NumberSeqModule"BaseEnum.
*************************************************************************************
6- Create a new Number Sequence Class Named "NumberSeqModuleModuleName"

7- Add a method "NumberSeqModule" to that class.

Method’s for NumberSeqModuleModuleName class –
1.Class Declaration:-
public class NumberSeqModuleOfficeManagement extends NumberSeqApplicationModule
{

}

2.NumberSeqModule:-
Public NumberSeqModulenumberSeqModule ()
{
  Return NumberSeqModule::OfcMgmt;
}
*************************************************************************************
8- Create a "Form" to display the new “parameter table's data”.
9- In Class "NumberSeqModuleModuleName" add override method "load module".
Coding  of Load Module =>
 Public void loadModule ()
 {
NumberSeqDatatypedatatype = NumberSeqDatatype::construct ();
;
//Gulshan
datatype.parmDatatypeId(extendedtypenum(CourierID));
datatype.parmReferenceHelp(literalstr("@SYS32633"));
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(99999);
datatype.parmSortField(1);
this.create (datatype);
}


10-To load "NumberSeqLoadModule" information for module, create “Job”.
Coding for Job =>
Public static void InstallOfficeManagement (Args _args)
{
NumberSeqModuleOfficeManagement n = new NumberSeqModuleOfficeManagement ();
  // NumberSeqModuleFacilityManagement n = new NumberSeqModuleFacilityManagement ();
n.loadModule ();
Print ("Job Executed Successfully");
Pause;
}
11-Now Setup "Number Sequence" just follows these steps;
    a) Go to CEU> Organization Administration
    b) Then Number Sequences > Number Sequences
    c) Click on "Number Sequence" in "New" tab.
    d) Fill the information in "Identification" tab.
    e) In "Scope parameters" tab select (Shred/Company)
    f) In "Segments" tab set the length of number sequence.
    g) Now in "General" setup click "continuous" option.
    h) Save and generate.
i) Click "close"

12-Now add "NumRef" method in "parameter table" name “NumRefEDTname”.Coding for NumRef Method :-
static client server NumberSequenceReferencenumRefCourierID()
{
returnNumberSeqReference::findReference(extendedTypeNum(CourierID));
}

13-In class declaration of a form add =>
Public class FormRun extends ObjectRun
{
NumberSeqFormHandlerNumberSeqFormHandler;
}
14-Add "NumberSeqFormHandler" method to the form.
Coding for NumberSeqFormHandler Method =>
NumberSeqFormHandlerNumberSeqFormHandler ()
{
If (!numberSeqFormHandler)
{
NumberSeqFormHandler = numberseqformhandler::newForm(OfcAdminParameters::numrefCourierTransID().NumberSequenceId,element,Courier_Invoice_Table_1_ds,fieldNum(Courier_Invoice_Table, CourierTransID));
}
Return NumberSeqFormHandler;
}

15-Write "close" method in form methods node and "link active, Validate write, Write, Delete" methods on methods     node of data source of form.
Coding  for “Close” Method=>
void close()
{
if (NumberSeqFormHandler)
{
numberSeqFormHandler.formMethodClose();
}
super();
}

Coding  fordatasource method’s:-
LinkActive =>
public void linkActive()
{
;
element.numberSeqFormHandler().formMethodDataSourceLinkActive();
super();
}

ValidateWrite :-
publicbooleanvalidateWrite()
{
boolean         ret;
ret = super();
ret = element.numberseqformhandler().formMethodDataSourceValidateWrite(ret) && ret;
if (ret)
{
Courier_Invoice_Table_1.validateWrite();
}
return ret;
}

Write:-
public void write()
{
super();
element.numberSeqFormHandler().formMethodDataSourceWrite();
}

Delete :-
public void delete()
{
element.numberSeqFormHandler().formMethodDataSourceDelete();
super();
}

Create =>
public void create(boolean _append = false)
{
;
super(_append);
//In the below line we have to write datasourcename.fieldname (very very important for number sequence)
  Courier_Invoice_Table_1.courierTransID = NumberSeq::newGetNum(OfcAdminParameters::numrefCourierTransID(),true).num();
Courier_Invoice_Table_1.InvoiceNumber = NumberSeq::newGetNum(OfcAdminParameters::numrefInvoiceNumber(),true).num();
Courier_Invoice_Table_1.VoucherNumber = NumberSeq::newGetNum(OfcAdminParameters::numrefVoucherNumber(),true).num();

}
........................................................
Other senario Table Methods:-
static FleetParameters find(boolean _forupdate = false)
{
FleetParameters  parameter = null;
;

parameter.selectForUpdate(_forupdate);

select firstonly parameter index Key where parameter.Key == 0;

if (!parameter && !parameter.isTmp())
{
Company::createParameter(parameter);
}

return parameter;
}

public static NumberSeqModule numberSeqModule()
{
return NumberSeqModule::FleetMngmt;
}

static client server NumberSequenceReference numRefFleetNum()
{
return NumberSeqReference::findReference(extendedTypeNum(fleetnumber));
}

static client server NumberSequenceReference numRefRouteId()
{
return NumberSeqReference::findReference(extendedTypeNum(RouteId));
}
........................................................................................................................................
FOrm Methods
public class FormRun extends ObjectRun
{
#HRMConstants

NumberSeqReference          numberSeqReference;
boolean                     runExecuteDirect;
TmpIdRef                    tmpIdRef;
NumberSeqScope             scope;
NumberSeqApplicationModule numberSeqApplicationModule;
container                  numberSequenceModules;
}

public void close()
{

super();
}
public void init()
{
this.numberSeqPreInit();
super();

this.numberSeqPostInit();
}

void numberSeqPostInit()
{
numberSequenceReference_ds.object(fieldNum(NumberSequenceReference, AllowSameAs)).visible(numberSeqApplicationModule.sameAsActive());

referenceSameAsLabel.visible(numberSeqApplicationModule.sameAsActive());
}

void numberSeqPreInit()
{
NumberSeqModule         module;
NumberSeqGlobal         global;
Map                     numseqmap;
NumberSeqModuleFleet    modulefleet = new NumberSeqModuleFleet();
;
runExecuteDirect = false;
numberSequenceModules = [NumberSeqModule::FleetMngmt];
numberSeqApplicationModule = new NumberSeqModuleFleet();
scope = NumberSeqScopeFactory::createDataAreaScope();
module = numberSeqApplicationModule.numberSeqModule();
Appl.numberSeqGlobal().numberSeqModulesMap().insert(NumberSeqModule::FleetMngmt,modulefleet);
NumberSeqApplicationModule::createReferences(NumberSeqModule::FleetMngmt);
tmpIdRef.setTmpData(NumberSequenceReference::configurationKeyTableMulti(numberSequenceModules));
}

FORM Number sequence referrence datasource methods:
void removeFilter()
{
runExecuteDirect = false;

numbersequenceReference_ds.executeQuery();
}

void executeQuery()
{
if (runExecuteDirect)
{
super();
}
else
{
runExecuteDirect = true;
this.queryRun(NumberSeqReference::buildQueryRunMulti(numberSequenceReference,
tmpIdRef,
numberSequenceTable,
numberSequenceModules,
scope));
numbersequenceReference_ds.research();
}
}

Number seq datasource table -> number sequenceid field  methods

public Common resolveReference(FormReferenceControl _formReferenceControl)
{
NumberSequenceCode code = _formReferenceControl.filterValue(
AbsoluteFieldBinding::construct(fieldStr(NumberSequenceTable, NumberSequence),
tableStr(NumberSequenceTable))).value();
return NumberSequenceTable::findByNaturalKey(code, scope.getId(true));
}

public Common lookupReference(FormReferenceControl _formReferenceControl)
{

NumberSequenceTable     selectedRecord;
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(NumberSequenceTable), _formReferenceControl, true);
Query lookupQuery;
;
sysTableLookup.addLookupfield(fieldNum(NumberSequenceTable, NumberSequence));
lookupQuery = new Query();
lookupQuery.addDataSource(tableNum(NumberSequenceTable)).addRange(fieldNum(NumberSequenceTable, NumberSequenceScope)).value(queryValue(scope.getId(true)));
sysTableLookup.parmQuery(lookupQuery);
selectedRecord = sysTableLookup.performFormLookup();
return selectedRecord;
}

---------------------------------------------------------------------------------------------------------------------------------------------------
CLass  Methods:

public class NumberSeqModuleFleet extends NumberSeqApplicationModule
{

}
protected void loadModule()
{
NumberSeqDatatype datatype = NumberSeqDatatype::construct();
;
datatype.parmDatatypeId(extendedtypenum(RouteId));
datatype.parmReferenceHelp("Route ID");
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999);
datatype.parmSortField(20);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);


datatype.parmDatatypeId(extendedtypenum(FleetNumber));
datatype.parmReferenceHelp("Fleet Number");
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999);
datatype.parmSortField(21);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
}

Public NumberSeqModule numberSeqModule()
{
  Return NumberSeqModule::FleetMngmt;
}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8