Filtering Data Entities in Dynamics 365 Finance & Operations to return only active records—such as those where an
EndDate is today or in the future—is a common integration requirementThe Scenario
Imagine you have a Data Entity with a parent table and a related child table joined on a common keyStartDate and EndDate fields that define how long a record remains valid
The Goal: Automatically exclude expired records so that every export or query returns only active data (
EndDate >= Today).
Why manual export filters fall short
The Solution: Add an AOT Range to the Root Data Source
By placing a query range directly on the root data source of your entity in Visual Studio, the range gets compiled straight into the entity's underlying metadata query
Step-by-Step Instructions
Open your entity in the Visual Studio designer
. Expand the tree: Go to Data Sources (this should be the main parent table)
. Add the Range: Right-click Ranges under that specific data source and select New Range
. Configure the Range properties:
Field: Select
EndDate. Value: Type
(greaterThanDate(0)). Enabled: Set to
Yes. Save & Sync: Save your changes, run a build on your project, and synchronize the database
.
How (greaterThanDate(0)) Actually Works
If you haven't run across greaterThanDate() before, it’s a standard SysQueryRangeUtil helper method built into Dynamics 365
Dynamic Execution: Rather than hardcoding a static date, this expression evaluates dynamically every time the query runs
. Day Offset: The number inside the parentheses represents a day offset relative to today
. Passing 0means "today" (0 = current date). Syntax Matters: Don't forget the surrounding parentheses
(). That wrapping tells the query parser to treat the text as a method call and resolve it before executing the SQL statement .
Comments
Post a Comment