Ax7 - 表单数据源字段

时间:2017-09-26 14:37:49

标签: axapta dynamics-ax7

我正在尝试在表单中的数据源字段中创建一个简单的查找。

表格和相关表格是BankAccountTable。

1.-新的BullCust(扩展EDT CustAccount)字段和新的扩展BankAccountTable.MyExtension。

2.-创建了新的表单扩展BankAccountTable.MyExtension并添加了新的表格组。

这很好用。但现在我想要一个更简单的查找。在Ax2012中,我会覆盖BankAccountTable \ Datasources \ BankAccountTable \ BullCust \ Lookup方法,如下所示:

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    SysTableLookup          sysTableLookup;

    sysTableLookup = SysTableLookup::newParameters(tableNum(ExcEC_DocuTypeTable), _formControl);
    queryBuildDataSource = query.addDataSource(tableNum(CustTable));

    sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
    sysTableLookup.addLookupField(fieldNum(CustTable, Party));
    sysTableLookup.addLookupField(fieldNum(CustTable, RecId));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

在Ax7中,这不再起作用了。试过这种方法(基于https://ievgensaxblog.wordpress.com/2016/05/01/ax-7-how-to-override-form-data-source-field-methods-without-overlaying/):

3.-创建管理查找的类:

public class BullFormBankAccountTable_Handler
{
public static BullFormBankAccountTable_Handler construct()
{
    return new BullFormBankAccountTable_Handler();
}

public void BankAccountTable_BullCust_OnLookup(FormDataObject _formDataObject, FormControl _formControl, str _filterStr)
{

    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    SysTableLookup          sysTableLookup;

    sysTableLookup = SysTableLookup::newParameters(tableNum(BullDocuTypeTable), _formControl);
    queryBuildDataSource = query.addDataSource(tableNum(CustTable));

    sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
    sysTableLookup.addLookupField(fieldNum(CustTable, Party));
    sysTableLookup.addLookupField(fieldNum(CustTable, RecId));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
}

4.-创建了用于订阅和链接相关事件的类扩展:

[ExtensionOf(formStr(BankAccountTable))]
final public class BullFormBankAccountTable_Extension
{
[FormDataSourceEventHandler(formDataSourceStr(BankAccountTable, BankAccountTable), FormDataSourceEventType::Initialized)]
public static void BankAccountTable_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e)
{
    var overrider = BullFormBankAccountTable_Handler::construct();

    _sender.object(fieldNum(BankAccountTable, BullCust)).registerOverrideMethod(methodStr(FormDataObject, lookup),
        methodStr(BullFormBankAccountTable_Handler, BankAccountTable_BullCust_OnLookup), overrider);
}

}

没有结果。我调试了BullFormBankAccountTable_Extension.BankAccountTable_OnInitialized()被正确调用。但结果查找是标准的,而不是我的查找。 关于如何执行此操作的任何想法或示例?

(PS:版本Ax7平台更新9)

2 个答案:

答案 0 :(得分:1)

我不会使用类扩展来解决这个问题,而是使用控件的OnLookup事件上的事件处理程序。只需订阅该事件并在某个事件处理程序类中处理它。

这是一个潜在的代码示例。我在这里假设数据源字段" BullCust"也是表单上的控件,因为它会覆盖表单控件而不是数据源字段

public class YourEventHandlers
{
    [FormControlEventHandler(formControlStr(BankAccountTable, BullCust), FormControlEventType::Lookup)]
    public static void PWSCertificateProvince_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        Query                   query = new Query();
        QueryBuildDataSource    queryBuildDataSource;
        SysTableLookup          sysTableLookup;


        sysTableLookup = SysTableLookup::newParameters(tableNum(BullDocuTypeTable), sender);
        queryBuildDataSource = query.addDataSource(tableNum(CustTable));

        sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
        sysTableLookup.addLookupField(fieldNum(CustTable, Party));
        sysTableLookup.addLookupField(fieldNum(CustTable, RecId));

        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}

注意:如果正在显示/生成框架查找表单,您可能需要取消超级调用,具体取决于您的用例。

使用:

  FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
  ce.CancelSuperCall();

答案 1 :(得分:0)

仅使用 FormControl 参数尝试:

public void BankAccountTable_BullCust_OnLookup(FormControl _formControl)
{
    //same code
}

我检查了它并且有效。