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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: