[转]How to add Search/Find/Filter functionality to Display method in dynamics AX – ww12345678 的部落格 | AX Helper
最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

[转]How to add Search/Find/Filter functionality to Display method in dynamics AX

AX 2009 William 2226浏览 0评论

Dynamics AX, can retrieve output values by using table field and display method. As we know, usually standard dynamics AX filter functionality is working only for table field. But sometimes we have to do filter functionality for display method too. Below I’m going to explain how to add a filter functionality for Display method.

1.    Here I have added display method (disCustName) to display customer name on the “IND_BusRelation” form. In this form main data source is “smmBusRelTable”.
2.   Change “AutoDeclaration” property from No to Yes of the “disCustName” data field.

3. Override “context()” method of the “disCustName” data field and add following code.

//注意:如果你想保留系统标准的上下文菜单,仅仅在其后添加自己的菜单项,请覆写showContextMenu()方法。

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: //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
                q   = smmBusRelTable_ds.query();
                qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
                qb1 = qb1.addDataSource(TableNum(CustTable));
                qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
                qb1.addRange(FieldNum(CustTable,Name)).value(strtext);
                smmBusRelTable_ds.query(Q);
                smmBusRelTable_ds.executeQuery();
            }
            break;

    case b:   // Filter By Selection
            q   = smmBusRelTable_ds.query();
            qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
            qb1 = qb1.addDataSource(TableNum(CustTable));
            qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
            qb1.addRange(FieldNum(CustTable,Name)).value(disCustName.valueStr());
            smmBusRelTable_ds.query(Q);
            smmBusRelTable_ds.executeQuery();
            break;
    case c :   // Remove Filter
            q   = new Query();
            qb1 = q.addDataSource(tablenum(smmBusRelTable));
            qb1.clearLinks();
            qb1.clearRanges();
            smmBusRelTable_ds.query(Q);
            smmBusRelTable_ds.removeFilter();
            break;

    Default:
            break;
    }

}

4. Run the form and do right Click on Customer Name field.

 

原文地址(GFW):http://dynamicsaxsolutionsworld.blogspot.com/2011/09/how-to-add-search-find-filter.html

转载请注明:ww12345678 的部落格 | AX Helper » [转]How to add Search/Find/Filter functionality to Display method in dynamics AX

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址