Search This Blog

Wednesday, November 20, 2013

How to add Filter functionality to Display method in dynamics AXAPTA

Hi Friends,


Normally filters will work only in table fields but we can't do filters to display method.

This below code will work for filters to display method also.

Step 1:
Go to the form design right click on particular control properties Auto Declaration No to Yes.



Step 2:
Override the context() method on the display method .

public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem('Filter By Field');
    int b = menu.insertItem('Filter By Selection');
    int c = menu.insertItem('Remove Filter');
    ;
q   = ItemControl_ds.query();
qb1 = q.dataSourceTable(tablenum(ItemControl));
qb1 = qb1.addDataSource(TableNum(SalesTable));
qb1.addLink(FieldNum(ItemControl,PO),FieldNum(SalesTable,PurchOrderFormNum));  

selectedMenu = menu.draw();
    switch (selectedMenu)
    {
    case -1: //Filter by field
            break;
    case a:
            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();
            if(strtext)
            {
//Creating a query for filter
                
                qb1.addRange(FieldNum(SalesTable,SearchName)).value(strtext);
                ItemControl_ds.query(Q);
                ItemControl_ds.executeQuery();
            }
            break;

    case b:                                      // Filter By Selection
           
            qb1.addRange(FieldNum(SalesTable,SearchName)).value(ProjName.valueStr());
            ItemControl_ds.query(Q);
            ItemControl_ds.executeQuery();
            break;

    case c :                                      // Remove Filter
            q   = new Query();
            qb1 = q.addDataSource(tablenum(ItemControl));
            qb1.clearLinks();
            qb1.clearRanges();
            ItemControl_ds.query(Q);
            ItemControl_ds.removeFilter();
            break;

    Default:
            break;
    }

}
After adding the above code we are getting menus like 


Happy Daxing..



1 comment: