简体   繁体   English

Dynamics AX:在代码中禁用表单中的数据源,同时能够使用高级过滤/排序选项

[英]Dynamics AX: Disable datasource from form in code while being able to use advanced filter/sort option

I've modified the InventTable form so the users can filter the items depending on their "Stopped" status on the default order settings setup form. 我修改了InventTable表单,以便用户可以根据默认订单设置设置表单中的“已停止”状态过滤项目。 They get a list of the "buyable" items, "sellable" items, all items or blocked items for sale or purchase depending of the values of two checkboxes. 根据两个复选框的值,他们会获得“可购买”商品,“可销售”商品,所有商品或已阻止商品的列表,以供销售或购买。

I've added the InventItemSalesSetup and InventItemPurchSetup datasources in the code and I enable or disable them when the user checks or unchecks a checkbox. 我在代码中添加了InventItemSalesSetup和InventItemPurchSetup数据源,并在用户选中或取消选中复选框时启用或禁用它们。

Everything works fine except when one of the datasources is disabled. 除非禁用其中一个数据源,否则一切正常。 Then the "Advanced filter/sort" option stops working. 然后“高级过滤/排序”选项停止工作。 I get the error: "The data source is not enabled". 我收到错误:“数据源未启用”。

The error comes from the method "saveCueEnabled" of the SysQueryForm form. 该错误来自SysQueryForm表单的方法“saveCueEnabled”。 When it calls: 当它打电话:

if (!CueRun::canSaveQueryAsCue(this.args().caller()))
    return false;

Which calls: 哪个电话:

static boolean canSaveQueryAsCue(QueryRun qr)
{
    int numOfDataSources, i;
    QueryBuildDataSource ds;
    Query q;
    Common cursor;
    ;

    if (!qr)
    return false;

    q = qr.query();
    if (!q)
        return false;

    numOfDataSources = q.dataSourceCount();
    for(i = 1; i <= numOfDataSources; i++)
    {
        ds = q.dataSourceNo(i);
        if(ds.dynalinkCount() > 0)
            return false;

        // Check if it is temp
        cursor = qr.getNo(i);
        if (cursor.dataSource() && cursor.isTmp())
            return false;
    }

    return true;
}

When it gets the number of the datasources in the query, the "dataSourceCount" method also returns the count with the disabled data sources, and when it gets the QueryBuildDataSource of the disabled data sources in the loop you get an empty DS and it crashes when it checks if it's a temporary table. 当它获取查询中的数据源数量时,“dataSourceCount”方法也会返回带有已禁用数据源的计数,当它获取循环中已禁用数据源的QueryBuildDataSource时,会得到一个空DS并且当它崩溃时崩溃它检查它是否是临时表。

I've solved the problem adding an extra if on the "saveCueEnabled" code but I wonder if there's a way to enable/disable the data sources without getting this error. 我已经解决了在“saveCueEnabled”代码上添加额外if的问题,但我想知道是否有一种方法可以启用/禁用数据源而不会出现此错误。

I hope I've explained myself well, thank you! 我希望我能很好地解释自己,谢谢!

The only solution I can come up with requires you to modify canSaveQueryAsQue(). 我能提出的唯一解决方案要求您修改canSaveQueryAsQue()。

This update to the for loop is simple and should solve your issue. 对for循环的此更新很简单,应该可以解决您的问题。

for(i = 1; i <= numOfDataSources; i++)
{
    ds = q.dataSourceNo(i);
    if(ds && ds.dynalinkCount() > 0)
        return false;

    // Check if it is temp
    cursor = qr.getNo(i);
    if (cursor.dataSource() && cursor.isTmp())
        return false;
}

I have not tested this code, but I have used similar code in other situations. 我没有测试过这段代码,但我在其他情况下使用了类似的代码。 Hope that helps! 希望有所帮助!

The suggested edit doesn't actually work because the 'ds' variable is still 'truthy' when tested. 建议的编辑实际上不起作用,因为'ds'变量在测试时仍然是'truthy'。

The following seems to work: 以下似乎有效:

for(i = 1; i <= numOfDataSources; i++)
{
    ds = q.dataSourceNo(i);
    if(ds.enabled() && ds.dynalinkCount() > 0)
        return false;

    // Check if it is temp
    if(ds.enabled())
    {
        cursor = qr.getNo(i);
        if (cursor.dataSource() && cursor.isTmp())
            return false;
    }
}

Adding the '.enabled()' property to the test allows the code to skip over the disabled data sources as requested. 将“.enabled()”属性添加到测试允许代码根据请求跳过禁用的数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM