Home > Ax Technical > Dev tip: Finding if a range is specified in a query – Dynamics Ax

Dev tip: Finding if a range is specified in a query – Dynamics Ax

Here is a simple tip.

Recently i had a requirement which wanted to validate if a range has been entered in a query. The obvious approach would be running through the ranges in the query data sources and verify if each of them has a range. When you have multiple data source this is obviously not an interesting way to solve it and can be fooled around by just entering a value like ‘*’. So i was thinking out on a better approach and luckily i seemed to find it. Here it goes, the idea is to get the count of the records through the Query and get the count of the records directly through a DML, when compared if they are equal then there is no range entered.


InventTable inventTable;
int cntTotal;
;

cntTotal = SysQuery::countTotal(gQueryRun);

select count(recid) from inventTable;

if (inventTable.RecId == cntTotal)
{
throw error('Atleast one range must be specified for the item selection.');
}

Where can this be used ?

You can put it to use to prevent long running reports http://bit.ly/1bzGHVE to ensure that there are proper ranges.

Related articles