Saturday, July 25, 2015

Enable filter option in Display method Ax 2012

/// To Enable filter option in Display method Ax 2012


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');
    ;

    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   = TestDisplayLkp_ds.query();
                qb1 = q.dataSourceTable(tablenum(TestDisplayLkp));
                qb1 = qb1.addDataSource(TableNum(InventTable));
                qb1.addLink(FieldNum(TestDisplayLkp,ItemId1),FieldNum(InventTable,ItemId));
                qb1.addRange(FieldNum(InventTable,NameAlias)).value(strtext);
                TestDisplayLkp_ds.query(Q);
                TestDisplayLkp_ds.executeQuery();
            }
            break;

    case b:
            q   = TestDisplayLkp_ds.query();
            qb1 = q.dataSourceTable(tablenum(TestDisplayLkp));
            qb1 = qb1.addDataSource(TableNum(InventTable));
            qb1.addLink(FieldNum(TestDisplayLkp,ItemId1),FieldNum(InventTable,ItemId));
            qb1.addRange(FieldNum(InventTable,NameAlias)).value(strtext);
            TestDisplayLkp_ds.query(Q);
            TestDisplayLkp_ds.executeQuery();
            break;
    case c :
            q   = new Query();
            qb1 = q.addDataSource(tablenum(TestDisplayLkp));
            qb1.clearLinks();
            qb1.clearRanges();
            TestDisplayLkp_ds.query(Q);
            TestDisplayLkp_ds.removeFilter();
            break;

    Default:
            break;
    }

}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...