Imagine you’re running a modern warehouse for a company that manufactures and sells consumer electronics. Behind the scenes of Dynamics 365 Finance and Operations (and its predecessor AX), there’s a programming language called X++. This language looks like a cousin of C#, but it is tightly integrated into the Dynamics application layer. Developers use it to customize business logic, validate data, and control how forms and tables behave.
In our warehouse, when a retail clerk checks inventory for a tablet device, or when a manufacturing planner reviews raw materials, the logic that pulls, filters, and displays that data often depends on small X++ methods written against the form’s data sources.
What is “x++ add range to form datasource”
A form data source is like the lens through which a form sees its table data. Adding a range means applying a filter—only showing the rows that meet certain criteria. For example, in a warehouse screen you might only want to show stock records where the on-hand quantity is below a reorder threshold. That’s where you use x++ add range to form datasource.
When you add a range, you attach conditions directly to the query of the form’s data source, so every time the form loads or refreshes, it only shows matching records.
Example with Chain of Command
Suppose our electronics company wants a warehouse form to display only shipments where the status is “AwaitingPick” and the site is “MAIN.” We’ll use Chain of Command so we don’t modify the base form directly, but extend its behavior instead.
/// Extension class for the form data source
[ExtensionOf(formDataSourceStr(WHSLoadTable, WHSLoadLine))]
final class WHSLoadLine_ds_Extension
{
public void executeQuery()
{
QueryBuildDataSource qbs;
QueryBuildRange qbrStatus, qbrSite;
// Access the current form query
qbs = this.query().dataSourceTable(tableNum(WHSLoadLine));
// Filter shipments by status
qbrStatus = qbs.addRange(fieldNum(WHSLoadLine, LoadStatus));
qbrStatus.value(queryValue(WHSLoadStatus::AwaitingPick));
// Add a second filter for site MAIN
qbrSite = qbs.addRange(fieldNum(WHSLoadLine, InventSiteId));
qbrSite.value(queryValue("MAIN"));
next executeQuery(); // Chain of Command call
}
}
Here, the system quietly narrows the data so the warehouse clerk sees only lines that still need picking, and only at the main warehouse.
Expanding the scenario
Sometimes, your logistics manager might ask: “how can we add ranges to your form data sources dynamically?” Maybe the filter depends on which customer segment the clerk selected. In those cases, you can evaluate conditions at runtime inside executeQuery().
If you want to look across retail discounts as part of a promotions form, you could add range to your data source like this:
QueryBuildRange promoRange;
promoRange = qbds.addRange(fieldNum(RetailPeriodicDiscount, DiscountCode));
promoRange.value(queryValue("ELEC2025"));
This pattern can be shifted: “how can we add ranges to form data sources when we need multiple joins?” In that case you might Add a second datasource with X++—for example, link a manufacturing orders table to warehouse lines and then apply ranges to your form data source on the joined QBDS.
Wrapping up
In the everyday rhythm of a manufacturing and retail warehouse, these filters keep screens relevant, showing only the electronic shipments or discount codes the clerk needs. With X++, you don’t just query data—you guide the user’s workflow, focusing attention on the right slice of operational reality.
Have a Question ?
Fill out this short form, one of our Experts will contact you soon.
Talk to an Expert Today
Call Now