Hello everyone,
I am new at X++ and I am trying to decipher the code below. If someone could explain what the code below is doing. I would appreciate it.
/// <summary>
/// Builds the query to use to load the estimated cost.
/// </summary>
/// <returns>
/// The query to use for loading estimated cost.
/// </returns>
protected Query buildEstimateQuery()
{
Query query;
QueryBuildRange qbrLevel;
QueryBuildRange qbrOrCondition;
query = new Query(queryStr(BOMCalcSum));
SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(BOMCalcTrans)), fieldNum(BOMCalcTrans, PriceCalcId)).value(queryValue(inventItemPrice.PriceCalcId));
// Loop through the records using the lineNum
query.dataSourceTable(tableNum(BOMCalcTrans)).addSortField(fieldNum(BOMCalcTrans, LineNum));
query.dataSourceTable(tableNum(BOMCalcTrans)).orderMode(OrderMode::OrderBy);
if (! isCostBreakdownActivated)
{
qbrLevel = SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(BOMCalcTrans)), fieldNum(BOMCalcTrans, Level));
qbrLevel.value(queryValue(1));
}
else
{
qbrOrCondition = SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(BOMCalcTrans)), fieldNum(BOMCalcTrans, Resource));
// Add an or Condition:
// Everything that is level single or not bom
qbrOrCondition.value(strFmt('((%1.%2 == %3) || (%1.%4 == %5))',
query.dataSourceTable(tableNum(BOMCalcTrans)).name(), // BOMCalcTrans %1
fieldStr(BOMCalcTrans, Level), // Level %2
any2int(InventCostLevel::Single), // 1 (= Level Single) %3
fieldStr(BOMCalcTrans, bom), // BOM %4
any2int(NoYes::No))); // No %5
qbrOrCondition.status(RangeStatus::Hidden);
}
return query;
}
Please re-post your code with line indentation, because it makes it much easier to read. Use Insert > Code in the rich-formatting view.
Then tell us which part(s) of the code you don't understand.
I'll change the category of this question to Development / Customization / SDK.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156