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.
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(); }
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).
Martin Dráb
501
Most Valuable Professional
Saalim Ansari
313
Abhilash Warrier
310