Always use recId to know if a select statement returns a record

In Axapta, there are two options to know if a select statement returns a record.

Option 1:
select purchTable where
purchTable.purchId == “Do not exist“;
if (purchTable)
{
…//Your logic here
}

Option 2:
select purchTable where
purchTable.purchId ==Do not exist“;
if (purchTable.recId)
{
…//Your logic here
}

It is strongly recommended to use recId. Because when working with aggregate functions in select statement. Table reference will always exist no matter a record is returned or not, but recId will be 0.
e.g.
select count(purchId) purchTable where
purchTable.purchId ==Do not exist“;
if (purchTable)
{
info(“The record exists!“);
}

It will present the user “The record exist!” even there is no record returned.

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: