Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

If check after select from table

(0) ShareShare
ReportReport
Posted on by

String abc;

Select firstOnly vendTable where vendTable.Id == 'US-111';

if(vendTable){

abc = vendTable.Name;

}

EDIT:

VendTable vendTable;
str abc;

select firstOnly vendTable
	where vendTable.AccountNum == 'US-111';

if (vendTable)
{
	abc = vendTable.name();
}

My question is: is the if statement necessary after the select statement.

I'm thinking that the if statement is unnecessary and i can just do the asssignment directly. (abc = vendTable.Name).

if vendTable returns empty, then abc will default to empty string. Wonder if my understanding is correct here.

  • Martin Dráb Profile Picture
    233,724 Most Valuable Professional on at
    RE: If check after select from table

    Another bug in the code is using 'string' instead of 'str'; and you probably meant AccountNum field instead of Id.

    By the way, please Use > Insert Code (in the rich formatting view to paste source code - it makes code easier to read and work with. For example:

    str abc;
    
    select firstOnly vendTable
    	where vendTable.AccountNum == 'US-111';
    
    if (vendTable)
    {
    	abc = vendTable.name();
    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: If check after select from table

    For me "necessary" means that the solution will not work without it.  Actually your code will not even compile (no matter if you have the condition there or not), because VendTable doesn't have a field called Name in AX2012.

    However VendTable has a method called name(), which returns the name of the vendor. Calling that method and executing the logic in it adds more overhead than checking "if (vendTable)" so in my opinion having the check is recommended (but not functionally necessary).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 501 Most Valuable Professional

#2
Saalim Ansari Profile Picture

Saalim Ansari 313

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 310

Overall leaderboard

Product updates

Dynamics 365 release plans