How to use args for CallerForm, Caller Table, Caller menu item and refresh primary datasource form while clicking OK on other forms
The Args class is used to pass arguments such as a name, a caller, and parameters between application objects.
in Form Init / Class main method ;
FormRun callerForm = element.args().caller();
TableId callerTableId = element.args().dataset();
MenuItemName callerMenuItemName = element.args().menuItemName();
------------------------------------------------------------------------------------------------------------------------
if (element.args().caller())
{
switch(callerForm.name())
{
case formStr(RetailInfocodeTable):
addProductsVariantsActionPane.visible(false);
rightGroup.visible(false);
break;
}
------------------------------------------------------------------------------------------------------------------------
switch (callerTableId)
{
case tableNum(RetailAssortmentTable):
retailAssortmentTable = element.args().record();
element.createToRBOAssortmentItemList(retailAssortmentTable, callerRecord.dataSource());
break;
}
Here lets consider , we update some records from caller table by opening a form where we have above code written,
now after updating the record in caller table, we need to refesh the caller datasoure after clicking on OK cliced method of called form
look at the last two line in the createToRBOAssortmentItemList method. look the RetailsAdditems form in the standard
void createToRBOAssortmentItemList(RetailAssortmentTable _assortmentTable, Object _callerDataSource)
{
RetailAssortmentProductLine assortmentProductLine;
assortmentProductLine.createFromTmpProductsToAdd(_assortmentTable, tmpInventTable, productsToAdd);
inventTable_ds.executeQuery();
_callerDataSource.findRecord(RetailAssortmentTable::findRecId(_assortmentTable.RecId));
_callerDataSource.refresh();
}
------------------------------------------------------------------------------------------------------------------------
The below code is only for form:
Switch(callerMenuItemName)
{
Case menuitemDisplayStr(RetailAddProductsVariants):
if(callerTableId == tableNum(RetailAssortmentTable) ||
callerForm.name() == formStr(RetailKitConfigure) ||
callerTableId == tableNum(DlvMode) ||
callerForm.name() == formStr(RetailCategory))
{
//disabled ItemGroup, buyerGroup & vendor for Global products.
itemGroup.enabled(false);
buyersGroup.enabled(false);
vendor.enabled(false);
tmpInventTable_ds.object(fieldNum(TmpRetailProductsToAdd, Quantity)).visible(false);
showQty = false; // Not to show field Quantity on the Matrix pivot form.
inventTable_ds.query().dataSourceTable(tableNum(InventTable)).enabled(false);
}
else
{
inventTable_ds.query().dataSourceTable(tableNum(InventTable)).enabled(true);
}
}
------------------------------------------------------------------------------------------------------------------------
Caller
|
Gets or sets the instance of the object that
created this instance of the Args class.
|
name
|
Gets and sets the name of the application object to
call.
|
parm
|
Gets or sets a string that specifies miscellaneous
information for the called object.
|
parmEnum
|
Gets or sets the enumeration value of the
enumeration type that is specified in the parmEnumType method.
|
parmEnmType
|
Gets or sets the ID value of any enumeration
type.
|
ParmObject
|
Gets or sets an instance of any object to pass to
the called object.
|
record
|
Gets and sets the record from the table on which
the caller object is working.
|
Example 1:
void clicked()
{
Args args = new Args();
;
args.caller(this);//know the exact use of this....
//args.record(Calling::find('Vinay'));
args.parm("hello");
args.parmEnumType(Enumnum(ABC));
args.parmEnum(ABC::B);
args.record(calling);
new MenuFunction(MenuItemDisplayStr(CallerMI),MenuItemType::Display).run(Args);
}
Code Written in Init of Caller Object
public void init()
{
Calling calling;
;
super();
info(element.args().parm());
info(element.args().parmEnum());
calling = element.args().record();
info(Calling.Firstname);
}
__
Example 2:
There are four methods that can be used to pass extra information to the new class:
The parm method – to pass strings
The parmEnum and parmEnumType method – to pass enumeration values
The parmObject method – to pass an object of any type.
Examples:
1. If you need a data from the parent form main data source for the current record, so you don’t need to do anything in parent, just create a display menu item and give the form name that needs to be opened, create a menuItem button and assign the newly created menu item.
Override the Init method on opened form
And you get the parent dataset records as
element.args().record()
2. Need to pass any object/string/Enum
Use the same approach for creating the button
Parent form
void clicked()
{
Args args;
FormRun formRun;
super();
args = new Args(formstr(FormName));
// To pass any string value
args.parm(<string value>);
// To pass any object
args.parmObject(<object>);
// To pass any Enum
args.parmEnum( EnumValue);
args.parmEnumType( EnumNum( <EnumName>) );
formRun = classFactory.FormRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
formRun.detach();
parenttable_ds.refresh(); // Refreshing parent table DataSourceTable
parenttable_ds.executeQuery(); // Refreshing Parent DataSourceTable
}
Child Form
void init()
{
args = element.args();
// get string parameter
<string> = args.parm();
// get object parameter
<object> = args.parmObject();
// get enum parameter
if( element.args().parmEnumType() == EnumNum( <EnumName>) )
{
<enum contol/variable> =( element.args().parmEnum() );
}
}
3. There are many parameters that you need to pass to the child form.
In that scenario, you need to create an extra class (parameter/contract class), you can first set the parameters in the init method for that class, use the parmObject for setting and gets the object on the child form
For more info:
http://msdn.microsoft.com/en-in/library/args.aspx
Comments
Post a Comment