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.

If a method does not return anything, you must specify this with the void keyword.

void methodName()

{

    ...

}

If a method returns something, you must specify the return type and include a return statement.

int methodName()

{

    return myInt;

}

Method declaration

=

Heading  Body

Heading

=

[ Modifiers ]  ReturnType  MethodName  (  ParameterList  )

Modifiers

=

[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 Note

If you use the anytype return type, the method can return any data type.

Aa584699.collapse_all(en-us,AX.60).gifMethod 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;
}

Aa584699.collapse_all(en-us,AX.60).gifMethod 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.

Aa584699.collapse_all(en-us,AX.60).gifMethods 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.

Community Additions

ADD
Show: