在Axapta/Dynamics Ax中对链接表进行过滤

问题描述:

我在Axapta/Dynamics Ax(EmplTable)中有一个表单,该表单具有两个数据源(EmplTable和HRMVirtualNetworkTable),其中第二个数据源(HRMVirtualNetworkTable)通过延迟"链接类型链接到第一个数据源.

I have a form in Axapta/Dynamics Ax (EmplTable) which has two data sources (EmplTable and HRMVirtualNetworkTable) where the second data source (HRMVirtualNetworkTable) is linked to the first on with "Delayed" link type.

是否有一种方法可以基于第二个数据源在记录上设置过滤器,而不必将链接类型更改为"InnerJoin"?

Is there a way to set an filter on the records, based on the second data source, without having to change the link type to "InnerJoin"?

在HRMVirtualNetworkTable上搜索字段时,可以使用外部联接"代替延迟",然后以编程方式更改联接模式.

You could use "Outer join" instead of "Delayed" then change the join mode programmaticly when there is search for fields on HRMVirtualNetworkTable.

将此方法添加到SysQuery类中:

Add this method to class SysQuery:

static void updateJoinMode(QueryBuildDataSource qds)
{
    Counter r;
    if (qds)
    {
        qds.joinMode(JoinMode::OuterJoin);
        for (r = 1; r <= qds.rangeCount(); r++)
        {
            if (qds.range(r).value() && qds.range(r).status() == RangeStatus::Open)
            {
                qds.joinMode(JoinMode::InnerJoin);
                break;
            }
        }
    }
}

在EmplTable数据源上的executeQuery()中:

In the executeQuery() on the EmplTable datasource:

public void executeQuery()
{;
    SysQuery::updateJoinMode(this.queryRun() ? this.queryRun().query().dataSourceTable(tableNum(HRMVirtualNetworkTable)) : this.query().dataSourceTable(tableNum(HRMVirtualNetworkTable)));    
    super();
}

有时this.queryRun()返回null,请改用this.query().

Sometimes this.queryRun() return null so use this.query() instead.

更新:

请注意,以上内容与AX 2012及更高版本无关,在AX 2012和更高版本中,您可以在外部联接中使用查询过滤器.请参见如何在外部联接中使用QueryFilter类.

Note that the above is not relevant for AX 2012 and later, where you can use query filters in outer joins. See How to Use the QueryFilter Class with Outer Joins.