Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

BOMCalcTrans: Need help to decipher X++ code

Posted on by 5

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;
}

  • Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: BOMCalcTrans: Need help to decipher X++ code

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans