Search This Blog

Thursday, April 25, 2013

Args class in Axapta


 

The Args system class is one of the most widely used classes in Axapta.
 Args is an abbreviation for arguments and an Args object is used to
pass information from one object (caller) to another newly created object.

Using Args for object creation
Args    args = new Args("CustTable");
FormRun formRun = ClassFactory.formRunClass(args);
;
formRun.init();
formRun.run();
formRun.wait();

caller:

public Object caller( [Object _value] )

This method gets or sets the calling object.
 When creating an args object directly through code,
 the caller will not be automatically set, so you should set it yourself.

Record:

public Common record( [Common _value] )

this method gets or sets a table buffer (record) attached to the Args.
 A buffer of any table can be attached to an Args object using this method. 
Be aware when retrieving the buffer that there will be no compile-time check of table id. 
You should use the dataset method below to check the contents of the buffer.
If the caller and callee are on different tiers, 
then the applications will automatically copy the buffer to the target tier.

Dataset:

public tableId dataset()

this method gets the table Id of a table buffer (record) attached to the Args.
To safely retrieve an attached record from an Args object,
use code similar to that shown below.
This checks to ensure that there is an attached record,
and that it is in fact a SalesTable record, before trying to assign it to the salesTable variable.

if (args.record() && args.dataset() == tableNum(SalesTable))
salesTable = args.record();

parm:

public str parm( [str _value] )
parm is used to pass a string variable to the called object

parmEnum:

public anytype parmEnum( [int _value] )
see parmEnumType

parmEnumType:

public int parmEnumType( [int _value] )
parmEnum and parmEnumType are used together to pass a Base Enum value through to the called object. An example is shown below.
args.parmEnumType(EnumNum(AddressType));
args.parmEnum(AddressType::Delivery);

parmObject:

public Object parmObject( [Object _value] )
parmObject is used to pass a reference to any object to the called object.
Be aware of client-server issues if the caller and callee are on different tiers.

menuItemName:

public final str menuItemName( [str _value] )

menuItemType:

public final MenuItemType menuItemType( [MenuItemType _value] )
A short tutorial on how to open a form in Dynamics Ax (Axapta) by code.

Just take a line of code:

new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run();

The above code will open the CustTable form. That's all it takes.
Now if you want to supply some arguments to the opening form,
 this is also possible with the optional args parameter.

static void FormOpen()
{
Args args = new Args();
;
args.record(CustTable::find('CUS-001'));
new MenuFunction(MenuItemDisplayStr(CustTable),MenuItemType::Display).run(Args);
}

This code will open the CustTable form and filter out the
customer with accountnumber CUS-001.

Enjoy Daxing..

No comments:

Post a Comment