Posts

Showing posts with the label ranges

How to add empty ranges in query

In Dynamics AX programming, a common mistake I have seen when it comes to query ranges is passing an empty string value to the range. The developer here is expecting it to show all the records where the range field is empty. Instead, what we get is all records without the range being applied. As baffling as it may seems, it is easily explainable. The query engine in Dynamics AX, will not add a range if you don’t specify a value or if you specify an empty string because an empty string is treated as no value. So the following code will result in this SQL statement, query = new Query(); qbds = query.addDataSource(tableNum(ProjTable)); qbr = qbds.addRange(fieldNum(ProjTable, Name)); qbr.value(''); Select first fast * from ProjTable; But what was expected was something like, Select first fast * from ProjTable where Name == ''; So to work around this issue, use the SysQuery::valueEmptyString() static method which parses the empty strings correctly so that it...