Contact Me

Total Pageviews

Monday 1 September 2014

Accessor Methods(parm methods) in Axapta

In Dynamics AX classes, member variables are always protected. In other words, they can’t  be accessed outside of the class; they can be accessed only from within objects of the class or its subclasses. To access member variables from outside the class, you must write accessor methods. The accessor methods can get, set, or both get and set member variable values. All accessor methods start with parm. In Dynamics AX, accessor methods are frequently referred to as parm methods.

An Example is:

CustAccount parmCustAccount(CustAccount _custAccount  = custAccount)
{
;
    custAccount = _custAccount;

    return custAccount;
}


The below is the simple flow to create and use a class
                            


                           i.                In ClassDeclaration, declare a variable of the extended data type ItemId. ClassDeclaration should look like the following:

class MyFirstClass
{
ItemId itemId;
}


                            ii.             Now add an new method to the class by pressing ctrl+n. The new method called "Method1" will automatically be opened in the editor. Change the name of the method to "parmItemId".


                              iii.            Set the parameter variable equal to the global class variable itemId. The method must return itemId.

itemId parmItemId(ItemId _itemId = itemId)
{
;
itemId = _itemId;
return itemId;
}


As class variables cannot be referenced from outside the class, so you can create methods like this to set and get the values of a class variable. Such methods are often prefixed with parm*.


                            iv.            Click the save icon in the editor tool bar to save all changes to the class.Override the main() method of the class and write:




public static void main(Args _args)
{
  MyFirstClass myFirstClass;
  ;
  myFirstClass = new MyFirstClass();
  myFirstClass.parmItemId("Item100");
  info(myFirstClass.parmItemId());
}
Output:



1 comment: