Here I want filter on ItemGroupName field of InventOnHandItem form
You need to write display method on form datasource and pass buffer as parameter.
display ItemGroupId itemGroupId(InventSum _inventSum)
{
InventItemGroupItem inventItemGroup;
select ItemGroupId from inventItemGroup
where inventItemGroup.ItemId == _inventSum.ItemId
&& inventItemGroup.ItemDataAreaId == _inventSum.dataAreaId;
return inventItemGroup.ItemGroupId;
}
display Name inventItemGroupName(InventSum _inventSum)
{
return InventItemGroup::find(this.itemGroupId(_inventSum)).Name;
}
void context()
{
int selectedMenu;
real test;
formrun fr;
Args ag;
Name strtext;
querybuilddataSource qb1, qb2;
queryrun qr;
query q;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem('Find');
int b = menu.insertItem('Filter');
int c = menu.insertItem('Remove Filter');
selectedMenu = menu.draw();
switch (selectedMenu)
{
case -1:
break;
case a:
ag = new args('SysformSearch');
fr = new formrun(ag);
fr.run();
fr.wait();
strtext = fr.design().controlName('FindEdit').valueStr();
if(strtext)
{
q = InventSum_ds.query();
if ( ! q.dataSourceTable(tableNum(InventItemGroupItem)) )
{
qb1 = q.dataSourceTable(tablenum(InventSum));
qb1 = qb1.addDataSource(TableNum(InventItemGroupItem));
qb1.relations( false );
qb1.addLink(FieldNum(InventSum,ItemId),FieldNum(InventItemGroupItem,ItemId));
qb1.addLink(FieldNum(InventSum,DataAreaId),FieldNum(InventItemGroupItem,ItemDataAreaId) );
qb1.joinMode(JoinMode::ExistsJoin);
qb2= qb1.addDataSource( tableNum( InventItemGroup) );
qb2.relations( false);
qb2.addLink( fieldNum(InventItemGroupItem, ItemGroupId), fieldNum(InventItemGroup, ItemGroupId));
qb2.joinMode(JoinMode::ExistsJoin);
qb2.addRange(FieldNum(InventItemGroup,name)).value(queryValue(strtext));
InventSum_ds.query(Q);
}
else
q.dataSourceTable(tableNum(InventItemGroup)).addRange(FieldNum(InventItemGroup,name)).value(queryValue(strtext));
InventSum_ds.executeQuery();
}
break;
case b:
q = InventSum_ds.query();
if ( ! q.dataSourceTable(tableNum(InventItemGroupItem)) )
{
qb1 = q.dataSourceTable(tablenum(InventSum));
qb1 = qb1.addDataSource(TableNum(InventItemGroupItem));
qb1.relations( false );
qb1.addLink(FieldNum(InventSum,ItemId),FieldNum(InventItemGroupItem,ItemId));
qb1.addLink(FieldNum(InventSum,DataAreaId),FieldNum(InventItemGroupItem,ItemDataAreaId) );
qb1.joinMode(JoinMode::ExistsJoin);
qb2= qb1.addDataSource( tableNum( InventItemGroup) );
qb2.relations( false);
qb2.addLink( fieldNum(InventItemGroupItem, ItemGroupId), fieldNum(InventItemGroup, ItemGroupId));
qb2.joinMode(JoinMode::ExistsJoin);
qb2.addRange(FieldNum(InventItemGroup,name)).value(queryValue(this.valueStr()));
InventSum_ds.query(Q);
}
else
q.dataSourceTable(tableNum(InventItemGroup)).addRange(FieldNum(InventItemGroup,name)).value(queryValue(this.valueStr()));
InventSum_ds.executeQuery();
break;
case c :
InventSum_DS.query().dataSourceTable(Tablenum(InventItemGroup)).clearRanges();
InventSum_DS.executeQuery();
break;
Default:
break;
}
}