Args class

From Axaptapedia

Jump to: navigation, search

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.

Contents

[edit] Using Args for object creation

The Args object can also be used to assist in object creation, in conjunction with the ClassFactory. For example, to open a CustTable form, you can use the following code:

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

[edit] Methods and Properties

[edit] 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.

[edit] 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.

[edit] 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();

[edit] lookupField

public fieldId lookupField( [fieldId _value] )

see lookupValue

[edit] lookupValue

public str lookupValue( [str _value] )

lookupField and lookupValue are used together. When they are filled with a field Id and value, it indicates that a form opened using the current Args object will automatically select a record based on that criteria.

For example, the following code assumes that a customer with the account code "1000" exists. It will open the CustTable form with customer '1000' selected, but with the other customers still shown. This is the same result visually as is achieved using the Go to Main Table function in Axapta 3.0 and higher.

Args    args = new Args("CustTable");
 FormRun formRun;
 ;
 
 // Look up customer 1000 when the form opens
 args.lookupField(fieldNum(CustTable, AccountNum));
 args.lookupValue("1000");
 
 formRun = ClassFactory.formRunClass(args);
 
 formRun.init();
 formRun.run();
 formRun.wait();

Note that this lookup is extremely fast, and should be used in preference to calling .findValue or .findRecord once the form has opened.

[edit] parm

public str parm( [str _value] )

parm is used to pass a string variable to the called object

[edit] parmEnum

public anytype parmEnum( [int _value] )

see parmEnumType

[edit] 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);

[edit] 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.

[edit] menuItemName

public final str menuItemName( [str _value] )

[edit] menuItemType

public final MenuItemType menuItemType( [MenuItemType _value] )

[edit] Examples

Personal tools