How to apply AOT query ranges in D365FO?
In this article, I'm going to show you how to apply different types of ranges to AOT queries. We'll go through simple and complex ranges.
- Let's first create a simple query that has "CustTable" inner joined with "CustGroup"
- If we want the query to return values where AccountNum value is "US-001", we can add the string value US-001 directly
- Now what if you want to filter on AccountNum "US-001" OR "US-002", you can do it in two ways:
- you can either use comma to separate the values (comma is considered as an OR)
- Or, you can do it like this: ((AccountNum = "US-001") || (AccountNum = "US-002"))
This way will be helpful later when we do complex scenarios. But for simple scenarios you can stick with the first way - If we want to add another filter to the previous result, like filtering on the Yes/No field which is InclTax, then we can do the following:
- It's either we add a new range for this "InclTax" field so that it is considered as an AND to the previous result.
**You can filter by Yes/No or 0/1 - Or, you can add the whole filter on AccountNum field like this:
(((AccountNum = "US-001") || (AccountNum = "US-002")) && (InclTax = 1)) - Here you need to filter by 1 or 0 for the InclTax field (we can't use Yes/No)
- You don't have to put the range on the AccountNum field specifically, for example, you can write the whole expression on the InclTax field instead
- Make sure that each range is in parentheses
- Again, since the first method works, then we could do it the first way as it's simpler
- Now what if we want to add ranges on two datasources:
- If let's say we want to filter where CustTable.CreditMax < 10 AND CustGroup.Name = "Retail Customers", then we can do it as this:
- OR if we want to filter on CustTable.CreditMax < 10 OR CustGroup.Name = "Retail Customers", then we can do it as this (we'll need to do the range on one field because it's an OR between two different fields):
- it's either we put range on CreditMax field like this
((CreditMax<10) || (CustGroup.Name = "Retail Customers"))
or like this
((CustTable.CreditMax<10) || (CustGroup.Name = "Retail Customers")) - Or we can put the range on Name field like this:
((CustTable.CreditMax<10) || (Name = "Retail Customers"))
or like this
((CustTable.CreditMax<10) || (CustGroup.Name = "Retail Customers")) - Also when filtering AOT queries, we can utilize methods in "SysQueryRangeUtil" class that have [QueryRangeFunctionAttribute].
For example, I added a new date field to CustTable called "TestDate". And I wanted to add to the previous filter an AND condition that says "TestDate" field value should be greater than today's date by 2 days. In this case I can use the method "greaterThanDate(2)"
So if today is 27/9/2025, the condition will be TestDate > 29/9/2025
**Make sure to put parentheses when applying range value
- Also please note that you could use any method that has [QueryRangeFunctionAttribute] in the AOT query range, it doesn't have to be only inside "SysQueryRangeUtil" class.
For example, in HcmWorkerLookup class, you can use "currentWorker()" method in AOT ranges like this: (HcmWorkerLookup::currentWorker())
Comments
Post a Comment