The following is an example of filtering based on itemId selected.
Basically you have a form which has a grid at the top and item id , item group text fields where you need to select both item id and item group from the lookup and the grid is filtered based on the values selected.
1) In the class declaration :
class FormRun extends ObjectRun
{
InventTable inventTable; // create a buffer for the datasource
QueryBuildRange qbrItemId;
QueryBuildRange qbrItemGroup;
}
2) Add inventTable in the datasource node and write the following code in the init of that datasource
public void init()
{
QueryBuildDataSource qbds;
super();
qbds = this.query().dataSourceTable(tableNum(InventTable));
qbrItemId = qbds.addRange(fieldNum(InventTable, ItemId));
}
3) Add InventItemGroupItem in the datasource node and write override init
public void init()
{
QueryBuildDataSource qbds;
super();
qbds = this.query().dataSourceTable(tableNum(InventItemGroupItem));
qbrItemGroup = qbds.addRange(fieldNum(InventItemGroupItem, ItemGroupId));
}
4) Add ItemId stringedit form control to the design node and override modified method in the methods node and write the following code
public boolean modified()
{
boolean ret;
str value;
ret = super();
if(ret)
{
value = qbrItemId.value('*' + InventTable_ItemId1.valueStr() + "*");
InventTable_ds.executeQuery();
InventTable_ds.refresh();
InventTable_ds.research();
}
return ret;
}
NOTE :
In the above code InventTable_ItemId1 is the form control name whose auto declaration is set to yes.
5) Add ItemGroupId form control to design node and override lookup method
public void lookup()
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventItemGroup), this);
Query query = new Query();
QueryBuildDataSource qbdsInventItemGroup;
qbdsInventItemGroup = query.addDataSource(tableNum(InventItemGroup));
qbdsInventItemGroup.addOrderByField(fieldNum(InventItemGroup, ItemGroupId));
qbdsInventItemGroup.addRange(fieldNum(InventItemGroup, Name)).value(SysQuery::valueNotEmptyString());
sysTableLookup.addLookupfield(fieldNum(InventItemGroup, ItemGroupId),true);
sysTableLookup.addLookupfield(fieldNum(InventItemGroup, Name),false);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
6) Override modified method
public boolean modified()
{
boolean ret;
ret = super();
if(ret)
{
qbrItemGroup.value('*' + InventItemGroupItem_ItemGroup.valueStr() + '*');
InventTable_ds.executeQuery();
InventTable_ds.research();
}
return ret;
}
No comments:
Post a Comment