Dynamics AX 4.0 多表looup

时间:2022-05-11 21:29:49

project rar:http://files.cnblogs.com/files/sxypeace/PrivateProject_MutilTableLookupOnCtronl.rar

在AX 中控件的looup方法需要展示多表数据的时候,需要新建一个lookupFrom ,或者将所有数据写入临时表才能达到目的。

翻看了一下Class\sysTableLook,发现其实是动态创建form添加数据源显示控件来实现的。

于是new了一个新的Class\sysViewLook,来实现多表lookup。

public void lookup()
{ SysViewLookup SysViewLookup = new SysViewLookup();
query query = new query();
queryBuildDatasource qbds1;
queryBuildDatasource qbds2;
queryBuildDatasource qbds3;
; //must add by desc sorting
SysViewLookup.parmAddLookupTableId( tableNum(InventDim));
SysViewLookup.parmAddLookupTableId( tableNum(SalesLine));
SysViewLookup.parmAddLookupTableId( tableNum(SalesTable)); qbds1 = query.addDataSource(tableNum(SalesTable));
qbds2 = qbds1.addDataSource(tablenum(salesLine));
qbds2.relations( true);
qbds3 = qbds2.addDataSource(tableNum(InventDim));
qbds3.relations(true); sysQuery::findOrCreateRange( qbds2, fieldNum(salesLine,ItemId)).value("22MA*00K");
qbds1.addSortField( fieldNum(SalesTable,CreatedDate),SortOrder::Descending);
qbds1.addSortField( fieldNum(SalesTable,SalesId),SortOrder::Descending);
qbds1.addSortField( fieldNum(SalesTable,CustAccount),SortOrder::Ascending);
qbds2.addSortField( fieldNum(SalesLine,ItemId),SortOrder::Ascending);
qbds2.addSortField( fieldNum(InventDim,InventSizeId),SortOrder::Ascending); SysViewLookup.parmCallingControl( this);
SysViewLookup.addLookupfield( TableNum(salesTable), fieldNum(SalesTable,CreatedDate));
SysViewLookup.addLookupfield( TableNum(salesTable), fieldNum(SalesTable,SalesId),true);
SysViewLookup.addLookupfield( TableNum(salesTable), fieldNum(SalesTable,CustAccount));
SysViewLookup.addLookupfield( TableNum(SalesLine), fieldNum(SalesLine,ItemId));
SysViewLookup.addLookupfield( TableNum(InventDim), fieldNum(InventDim,InventSizeId)); SysViewLookup.parmQuery( query);
SysViewLookup.performFormLookup();
}

附完整代码的下载地址 http://files.cnblogs.com/files/sxypeace/PrivateProject_MutilTableLookupOnCtronl.rar