0
我需要計算任何特定維度的預算餘額(AX 2012 R2)。按代碼計算預算餘額
我執行以下代碼,但它需要很長時間才能完成。
這是因爲這個計算了AX的所有預算餘額,而不僅僅是我想要的。
最後,變量BudgetTmpBalance
它具有所有預算條目的記錄。
有什麼我不考慮。任何人都知道什麼是?
在此先感謝。
代碼:
BudgetTransactionLine recBudgetTransactionLine;
DimensionAttributeValueCombination recDimensionAttributeValueCombination;
date FiscalYearStart, FiscalYearEnd;
AccountingDistribution recAccountingDistribution;
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildDataSource qbdsJoin;
QueryBuildRange qbr;
BudgetCalculateBalance budgetCalculateBalance = new BudgetCalculateBalance();
BudgetTmpBalance budgetTmpBalance;
DimensionDisplayValue pDimensionDisplayValue;
;
pDimensionDisplayValue = "Correct Value";
select * from recDimensionAttributeValueCombination where recDimensionAttributeValueCombination.LedgerDimensionType == LedgerDimensionType::Budget &&
recDimensionAttributeValueCombination.DisplayValue == pDimensionDisplayValue;
FiscalYearStart = str2Date("01/04/" + int2str(year(today())), 123);
FiscalYearEnd = str2Date("31/03/" + int2str(year(today()) + 1), 123);
//Find recId of header that I Want (Works fine)
select BudgetTransactionHeader from recBudgetTransactionLine where recBudgetTransactionLine.LedgerDimension == recDimensionAttributeValueCombination.RecId &&
(recBudgetTransactionLine.Date >= FiscalYearStart && recBudgetTransactionLine.Date <= FiscalYearEnd);
qbds = query.addDataSource(tableNum(BudgetTransactionHeader));
qbr = qbds.addRange(FieldNum(BudgetTransactionHeader, TransactionStatus));
qbr.value(queryValue(1));
qbr = qbds.addRange(FieldNum(BudgetTransactionHeader, RecId));
qbr.value(queryValue(recBudgetTransactionLine.BudgetTransactionHeader));//Header RecId (correct value)
qbdsJoin= qbds.addDataSource(tableNum(BudgetTransactionLine));
qbdsJoin.relations(false);
qbdsJoin.fields().dynamic(NoYes::Yes);
qbdsJoin.addLink(fieldNum(BudgetTransactionHeader, RecId), fieldNum(BudgetTransactionLine, BudgetTransactionHeader));
qbdsJoin.joinMode(JoinMode::InnerJoin);
budgetCalculateBalance.parmDimensionFocus("CTA+UN+CC");
budgetCalculateBalance.parmCalculateLedgerAmounts(NoYes::Yes);
budgetCalculateBalance.parmFiscalCalendarRecId(Ledger::fiscalCalendar());
budgetCalculateBalance.parmStartDate(FiscalYearStart);
budgetCalculateBalance.parmEndDate(FiscalYearEnd);
budgetCalculateBalance.parmIncludeSubModels(NoYes::No);
budgetCalculateBalance.parmIncludeAllBudgetModelsIfNotSpecified(NoYes::No);
budgetCalculateBalance.parmBudgetModelId("TOTAL");
budgetCalculateBalance.parmBudgetType();
budgetCalculateBalance.parmAccumulateAmounts(NoYes::No);
budgetCalculateBalance.parmLedgerCategory(CurrentOperationsTax::Current);
budgetCalculateBalance.parmQuery(query);
budgetTmpBalance = budgetCalculateBalance.calculatePeriodBalances();