Declaration of Methods [AX 2012]
Updated: October 5, 2011
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
Methods are created using the Application Object Tree (AOT). When methods are created, MorphX creates a default declaration that must be altered.
Method declarations consist of a header and a body. The method header declares the name and return type (possibly void) of the method, the method modifiers, and parameters. The method body consists of variable declarations, method declarations, and statements.
|
Method declaration |
= |
Heading Body |
|
Heading |
= |
[ Modifiers ] ReturnType MethodName ( ParameterList ) |
|
= |
[client] [server] [edit | display | public | protected | private] [static | abstract | final ] | |
|
ReturnType |
= |
Datatype | void | anytype |
|
MethodName |
= |
Identifier |
|
ParameterList |
= |
[ Parameter { , Parameter }] |
|
Parameter |
= |
Datatype Variableidentifier [ = Expression ] |
|
Body |
= |
{ [ VariableDeclarations ] [ EmbeddedFunctionDeclarations ] [ Statements ] } |
|
EmbeddedFunctionDeclaration |
= |
Heading {[ VariableDeclarations ] [ Statements ]} |
Note
|
|---|
|
If you use the anytype return type, the method can return any data type. |
Method Without a Return Type
void update ()
{
// Variable declared and initialized
CustTable this_Orig = this.orig();
// First statement in body (begin transaction)
ttsBegin;
this.setNameAlias();
// Calls super's implementation of update
super();
this.setAccountOnVend(this_Orig);
if (this_Orig.custGroup != this.custGroup)
ForecastSales::setCustGroupId(
this.accountNum,
this_Orig.custGroup,
this.custGroup);
// Commits transaction
ttsCommit;
}
Method with Parameters
boolean checkAccountBlocked(AmountCur amountCur)
{
if (this.blocked == CustVendorBlocked::All
||(this.blocked == CustVendorBlocked::Invoice
&& amountCur > 0 ))
return checkFailed(strFmt("@SYS7987",this.accountNum));
return true;
}
checkAccountBlocked returns a Boolean value and acts on the parameter amountCur.
Methods with Modifiers
Only the method headers are shown in the following examples.
// A method that cannot be overridden final int dontAlterMe() // A static method static void noChange() // A display method that returns an integer display int value()
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.
Note