1

我有以下代码在 Req Trans 表上构建查询,以按项目/站点向我显示合并数量;

query = new Query();
dsReqTrans = query.addDataSource(tablenum(ReqTrans));

dsReqTrans.addRange(fieldnum(ReqTrans, ReqPlanId)).value(_reqPlanId);
dsReqTrans.addRange(fieldnum(ReqTrans, RefType)).value(enum2str(_reqRefType));

dsReqTrans.addGroupByField(fieldnum(ReqTrans, ItemId));
dsReqTrans.addSelectionField(fieldnum(ReqTrans, Qty),  SelectionField::Sum);

dsInventDim = dsReqTrans.addDataSource(tablenum(InventDim));
dsInventDim.joinMode(JoinMode::InnerJoin);
dsInventDim.relations(false);
dsInventDim.addLink(fieldnum(ReqTrans, CovInventDimId), fieldnum(InventDim, InventDimId));

dsInventDim.addGroupByField(fieldnum(InventDim, InventSizeId));
dsInventDim.addGroupByField(fieldnum(InventDim, InventSiteId));

rangeInventSiteId = dsInventDim.addRange(fieldnum(InventDim, InventSiteId));
rangeInventSiteId.value(_parmSiteId);

这很好用。我按项目/站点得到 qty 列的总和。

但是,如果我还想在 ItemGroupId 上添加一个范围。为此,我需要像这样链接到 InventTable;

dsInventTable = dsReqTrans.addDataSource(tablenum(InventTable));
dsInventTable.joinMode(JoinMode::InnerJoin);
dsInventTable.relations(false);
dsInventTable.addLink(fieldnum(ReqTrans, ItemId), fieldnum(InventTable, ItemId));

dsInventTable.addRange(fieldnum(InventTable, ItemGroupId)).value(_parmItemGroupId);

当我添加此数据源时,指向 InventDim 的链接已断开。我得到仅按项目分组的所有站点的所有项目数量的总和,而不是按项目/站点分组。

为什么会这样?

4

1 回答 1

3

基本上你不能有两个内部连接到同一个数据源(你可以,但它不起作用)。

如果使用 AX 2012,您可以将InventTable数据源添加到InventDim

dsInventTable = dsInventDim.addDataSource(tablenum(InventTable));
dsInventTable.joinMode(JoinMode::ExistsJoin);
dsInventTable.relations(false);
// OBS 3 arguments next:
dsInventTable.addLink(fieldnum(ReqTrans, ItemId), fieldnum(InventTable, ItemId), dsReqTrans.name()); 
dsInventTable.addRange(fieldnum(InventTable, ItemGroupId)).value(_parmItemGroupId);

在早期版本中,您InventTable首先放置(请记住按一个字段分组InventTable):

query = new Query(); 
dsInventTable = dsReqTrans.addDataSource(tablenum(InventTable)); 
dsInventTable.addGroupByField(fieldnum(InventTable, ItemId)); // You have to group/sum something
dsReqTrans = dsInventTable.addDataSource(tablenum(ReqTrans)); 
dsReqTrans.joinMode(JoinMode::InnerJoin); 
dsReqTrans.relations(false); 
dsReqTrans.addLink(fieldnum(InventTable, ItemId).fieldnum(ReqTrans, ItemId));
...
于 2012-04-24T11:37:46.543 回答