nerdexam
Microsoft

MB-500 · Question #198

Drag and Drop Question A company uses Dynamics 365 Finance. You must use QueryBuilder classes to implement a query that loops through all customers for whom the customer group equals EXT. You need to

The correct answer is Declare a QueryBuildDataSource object. Call the addDataSource method on the query object.; Declare a QueryBuildRange object and add a range for the CustGroup field on the QueryBuildDataSource object.; Add a value to range for the CustGroup EXT to the QueryBuildRange object.; Declare and initialize the QueryRun object by using the query object.; Loop through the QueryRun object by using the while loop.. QueryBuilder Query Implementation Order - Explained The Core Concept In Dynamics 365 Finance (X++), building a query follows a strict dependency chain: each object depends on the previous one existing first. You build the query structure top-down, then execute it bottom-up. The q

Develop business logic

Question

Drag and Drop Question A company uses Dynamics 365 Finance. You must use QueryBuilder classes to implement a query that loops through all customers for whom the customer group equals EXT. You need to implement the query. You declare and initialize a query Object. You need to run the query. in which order should you perform the actions? To answer, move all actions from the list of actions to the answer area and arrange them in the correct order. Answer:

Exhibit

MB-500 question #198 exhibit

Answer Area

Drag items

Declare a QueryBuildDataSource object. Call the addDataSource method on the query object.Declare a QueryBuildRange object and add a range for the CustGroup field on the QueryBuildDataSource object.Add a value to range for the CustGroup EXT to the QueryBuildRange object.Declare and initialize the QueryRun object by using the query object.Loop through the QueryRun object by using the while loop.

Correct arrangement

  • Declare a QueryBuildDataSource object. Call the addDataSource method on the query object.
  • Declare a QueryBuildRange object and add a range for the CustGroup field on the QueryBuildDataSource object.
  • Add a value to range for the CustGroup EXT to the QueryBuildRange object.
  • Declare and initialize the QueryRun object by using the query object.
  • Loop through the QueryRun object by using the while loop.

Explanation

QueryBuilder Query Implementation Order - Explained

The Core Concept

In Dynamics 365 Finance (X++), building a query follows a strict dependency chain: each object depends on the previous one existing first. You build the query structure top-down, then execute it bottom-up.

The question states the Query object is already declared and initialized - you're picking up from there.


Step-by-Step Breakdown

Step 1: Declare a QueryBuildDataSource object. Call the addDataSource method on the query object.

Before you can filter anything, you need to tell the query which table to query. QueryBuildDataSource represents a table (here, CustTable). You call query.addDataSource(tableNum(CustTable)) which both attaches the table to the query and returns the QueryBuildDataSource reference you store.

Why first? Ranges live on a data source. You cannot define a filter without a data source to attach it to. There is no parent yet, so this must come before any range work.


Step 2: Declare a QueryBuildRange object and add a range for the CustGroup field on the QueryBuildDataSource object.

Now you call dataSource.addRange(fieldNum(CustTable, CustGroup)) to create a range (filter slot) for the CustGroup field and store the returned QueryBuildRange reference.

Why second? You need the QueryBuildDataSource from Step 1 to call addRange on. The range is structurally attached to the data source - you're declaring what field to filter on, not what value yet.


Step 3: Add a value to range for the CustGroup EXT to the QueryBuildRange object.

Now you set the actual filter value: range.value("EXT"). This tells the query to only return records where CustGroup == "EXT".

Why third? You need the QueryBuildRange object from Step 2 to exist before you can assign a value to it. Separating "add range" from "set value" is intentional - the range object must be created first, then populated.


Step 4: Declare and initialize the QueryRun object by using the query object.

QueryRun qr = new QueryRun(query) wraps your fully configured Query object and prepares it for execution.

Why fourth? QueryRun takes a complete, configured Query as its argument. If you create QueryRun before adding the data source or range, those filters won't be applied. The entire query definition must be finalized before handing it to QueryRun.


Step 5: Loop through the QueryRun object by using the while loop.

while (qr.next()) { CustTable cust = qr.get(tableNum(CustTable)); } iterates through results.

Why last? You can only iterate results after the QueryRun is initialized. This is the execution phase - everything before this was definition phase.


Common Mistakes

MistakeWhy it's wrong
Creating QueryRun before adding rangesThe query runs without the EXT filter - returns all customers
Setting the range value before calling addRangeNo QueryBuildRange object exists to call .value() on
Skipping QueryBuildDataSource and going straight to rangesaddRange is a method on the data source - it doesn't exist yet
Looping before initializing QueryRunQueryRun doesn't exist; the loop has nothing to iterate

Mental Model

Think of it as building a pipeline before turning it on:

Table → Field Filter → Filter Value → Execution Engine → Run

Topics

#QueryBuilder#QueryBuildDataSource#QueryRun#X++ query

Community Discussion

No community discussion yet for this question.

Full MB-500 Practice