addAttributeRangeToQuery复制结果中的记录

时间:2016-10-11 15:02:17

标签: axapta dynamics-ax-2012 x++ dynamics-ax-2012-r3

我在查询的第一部分加入了GeneralJournalEntryGeneralJournalAccountEntry。我现在很难对MainAccount进行编码,因为我不确定如何正确使用DimensionProvider类。

query = new Query();

qbdsGeneralJournalAccountEntry = query.addDataSource(tableNum(GeneralJournalAccountEntry));
qbr1 = qbdsGeneralJournalAccountEntry.addRange(fieldNum(GeneralJournalAccountEntry, LedgerAccount));
qbr1.value(queryValue('111111') + '*');

qbdsGeneralJournalEntry = qbdsGeneralJournalAccountEntry.addDataSource(tableNum(GeneralJournalEntry));
qbdsGeneralJournalEntry.relations(true);
qbdsGeneralJournalEntry.joinMode(JoinMode::InnerJoin);


if (_fromDate || _toDate)
{
    qbdsGeneralJournalEntry.addRange(fieldnum(GeneralJournalEntry, AccountingDate)).value(queryRange(_fromDate, _toDate));
    qbdsGeneralJournalEntry.addSortIndex(indexNum(GeneralJournalEntry, LedgerAccountingDateIdx));
    qbdsGeneralJournalEntry.indexIsHint(true);
}



dimensionProvider = new DimensionProvider();
dimensionProvider.addAttributeRangeToQuery(
                     query
                   , qbdsGeneralJournalAccountEntry.name()
                   , fieldStr(GeneralJournalAccountEntr, LedgerDimension)
                   , DimensionComponent::DimensionAttribute
                   , _costCenterNumber
                   , "CostCenter");

我的所有行都被复制了..我想我再次添加GeneralJournalAccountEntry数据源,这就是我有这种行为的原因。

我可以查看while qr.next部分中的成本中心值但是..有没有办法使用上述方法正确执行:addAttributeRangeToQuery

1 个答案:

答案 0 :(得分:1)

好的,经过大量的尝试和搜索,再次尝试我得到了这个:

select firstOnly dimAttr where dimAttr.BackingEntityType == tableNum(DimAttributeOMCostCenter);
dimAttrNameCostCenter = dimAttr.Name;

query = new Query();


qbdsGeneralJournalEntry = query.addDataSource(tableNum(GeneralJournalEntry));

qbdsGeneralJournalAccountEntry = qbdsGeneralJournalEntry.addDataSource(tableNum(GeneralJournalAccountEntry));
qbdsGeneralJournalAccountEntry.relations(true);
qbdsGeneralJournalAccountEntry.joinMode(JoinMode::InnerJoin);

qbr1 = qbdsGeneralJournalAccountEntry.addRange(fieldNum(GeneralJournalAccountEntry, LedgerAccount));
qbr1.value(queryValue('111111') + '*');


if (_fromDate || _toDate)
{
    qbdsGeneralJournalEntry.addRange(fieldnum(GeneralJournalEntry, AccountingDate)).value(queryRange(_fromDate, _toDate));
    qbdsGeneralJournalEntry.addSortIndex(indexNum(GeneralJournalEntry, LedgerAccountingDateIdx));
    qbdsGeneralJournalEntry.indexIsHint(true);
}


dimensionProvider = new DimensionProvider();

dimensionProvider.addAttributeRangeToQuery(query
                                        , qbdsGeneralJournalAccountEntry.name()
                                        , fieldStr(GeneralJournalAccountEntry, LedgerDimension)
                                        , DimensionComponent::DimensionAttribute
                                        , _costCenterNumber
                                        , dimAttrNameCostCenter
                                        , false);

现在有效!!我刚刚切换了dataSources:

  1. 首先添加GeneralJournalEntry
  2. 添加GeneralJournalAccountEntry并将其加入" mother / father / header"表或其他任何东西:),即qbdsGeneralJournalEntry。
  3. 所以,不再是双胞胎,没有重复。我仍然想知道为什么内连接表现得像这样......

    明天我也会尝试为MainAccount使用addAttributeRangeToQuery,并在LedgerAccount上摆脱那个相当难看的范围。