You may find a lot of codes for the same purpose but the one which worked flawlessly for me is written below:
Write the below code in the executeQuery method of the root DS:
public void executeQuery()
{
super();
if(!queryObj)
{
queryObj = true;
existQuery = new Query(this.query());
existQuery.saved();
remFilQuery = new Query();
remFilQuery = existQuery;
remFilQuery = existQuery.makeCopy();
}
}
Now the context method in the display method control:
public void context()
{
int selectedMenu;
formrun fr;
Args ag;
Name strtext;
str filSel = ”;
querybuilddataSource qb1, qb2, qb3;
queryrun qr;
query q, q2;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem(‘Filter by field’);
int b = menu.insertItem(‘Filter by selection’);
int c = menu.insertItem(‘Clear’);
;
selectedMenu = menu.draw();
switch (selectedMenu)
{
case a: //Filter by field
ag = new args(‘SysformSearch’);
fr = new formrun(ag);
fr.run();
fr.wait();
//Reading User entered value for filter process
strtext = fr.design().controlName(‘FindEdit’).valueStr();
//strtext = ‘”‘ + fr.design().controlName(‘FindEdit’).valueStr() + ‘”‘;
if(strtext)
{
//Creating a query for filter
q = new Query(InventSerial_ds.query());
// existQuery = InventJournalTrans_ds.query();
qb1 = q.dataSourceTable(tablenum(InventSerial));
qb2 = qb1.addDataSource(TableNum(EcoResProduct));
qb2.addLink(FieldNum(InventSerial,ItemId),FieldNum(EcoResProduct,DisplayProductNumber));
qb3 = qb2.addDataSource(tableNum(EcoResProductTranslation));
qb3.relations(true);
qb3.addRange(fieldNum(EcoResProductTranslation, Name)).value(strtext);
qb3.addRange(fieldNum(EcoResProductTranslation, LanguageId)).value(infolog.language());
InventSerial_ds.query(q);
InventSerial_ds.executeQuery();
}
break;
case b: // Filter By Selection3
q = new Query(InventSerial_ds.query());
qb1 = q.dataSourceTable(tablenum(InventSerial));
qb2 = qb1.addDataSource(TableNum(EcoResProduct));
qb2.addLink(FieldNum(InventSerial,ItemId),FieldNum(EcoResProduct,DisplayProductNumber));
qb3 = qb2.addDataSource(tableNum(EcoResProductTranslation));
qb3.relations(true);
filSel = ‘”‘ + ItemDesc.valueStr() + ‘”‘;
qb3.addRange(fieldNum(EcoResProductTranslation, Name)).value(filSel);
qb3.addRange(fieldNum(EcoResProductTranslation, LanguageId)).value(infolog.language());
InventSerial_ds.query(q);
InventSerial_ds.executeQuery();
break;
case c : // Remove Filter
InventSerial_ds.query(remFilQuery);
InventSerial_ds.executeQuery();
break;
Default:
break;
}
}
Credits: https://msddax.wordpress.com/2014/11/29/filter-on-the-display-method-using-context-method/
Write the below code in the executeQuery method of the root DS:
public void executeQuery()
{
super();
if(!queryObj)
{
queryObj = true;
existQuery = new Query(this.query());
existQuery.saved();
remFilQuery = new Query();
remFilQuery = existQuery;
remFilQuery = existQuery.makeCopy();
}
}
Now the context method in the display method control:
public void context()
{
int selectedMenu;
formrun fr;
Args ag;
Name strtext;
str filSel = ”;
querybuilddataSource qb1, qb2, qb3;
queryrun qr;
query q, q2;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem(‘Filter by field’);
int b = menu.insertItem(‘Filter by selection’);
int c = menu.insertItem(‘Clear’);
;
selectedMenu = menu.draw();
switch (selectedMenu)
{
case a: //Filter by field
ag = new args(‘SysformSearch’);
fr = new formrun(ag);
fr.run();
fr.wait();
//Reading User entered value for filter process
strtext = fr.design().controlName(‘FindEdit’).valueStr();
//strtext = ‘”‘ + fr.design().controlName(‘FindEdit’).valueStr() + ‘”‘;
if(strtext)
{
//Creating a query for filter
q = new Query(InventSerial_ds.query());
// existQuery = InventJournalTrans_ds.query();
qb1 = q.dataSourceTable(tablenum(InventSerial));
qb2 = qb1.addDataSource(TableNum(EcoResProduct));
qb2.addLink(FieldNum(InventSerial,ItemId),FieldNum(EcoResProduct,DisplayProductNumber));
qb3 = qb2.addDataSource(tableNum(EcoResProductTranslation));
qb3.relations(true);
qb3.addRange(fieldNum(EcoResProductTranslation, Name)).value(strtext);
qb3.addRange(fieldNum(EcoResProductTranslation, LanguageId)).value(infolog.language());
InventSerial_ds.query(q);
InventSerial_ds.executeQuery();
}
break;
case b: // Filter By Selection3
q = new Query(InventSerial_ds.query());
qb1 = q.dataSourceTable(tablenum(InventSerial));
qb2 = qb1.addDataSource(TableNum(EcoResProduct));
qb2.addLink(FieldNum(InventSerial,ItemId),FieldNum(EcoResProduct,DisplayProductNumber));
qb3 = qb2.addDataSource(tableNum(EcoResProductTranslation));
qb3.relations(true);
filSel = ‘”‘ + ItemDesc.valueStr() + ‘”‘;
qb3.addRange(fieldNum(EcoResProductTranslation, Name)).value(filSel);
qb3.addRange(fieldNum(EcoResProductTranslation, LanguageId)).value(infolog.language());
InventSerial_ds.query(q);
InventSerial_ds.executeQuery();
break;
case c : // Remove Filter
InventSerial_ds.query(remFilQuery);
InventSerial_ds.executeQuery();
break;
Default:
break;
}
}
Credits: https://msddax.wordpress.com/2014/11/29/filter-on-the-display-method-using-context-method/
No comments:
Post a Comment