Question about List in AX

Hi everyone,

I have the following code:

Solution (1):

1-1: List purchRFQVendLinkList = new List( tableNum( PurchRFQVendLink ) );

1-2: while select purchRFQVendLinkLocal

where purchRFQVendLinkLocal.RFQCaseId == purchRFQCaseTableLocal.RFQCaseId

{

purchRFQVendLinkList.addEnd(purchRFQVendLinkLocal);

}

Then, I have an error dialog which says the ‘The type is not as expected’;

If I change to

Solution (2):

2-1: List purchRFQVendLinkList = new List(Types::String);

2-2: while select VendAccount from purchRFQVendLinkLocal

where purchRFQVendLinkLocal.RFQCaseId == purchRFQCaseTableLocal.RFQCaseId

{

purchRFQVendLinkList.addEnd(purchRFQVendLinkLocal.VendAccount);

}

It works fine.

So, I am wondering why solution (1) cannot work, the declaration of 1-1 is not right? I know “List” in AX can contain any type of X++ object, right? It’s a little weird to me now.

Thank you,

Kwen

List’s constructor expects a value from Types enumeration, e.g. Types::Record.

You call it as new List(tableNum(…)) - tableNum() returns an int value, which is compatible with the enum parameter (enum values are just named numbers). so you don’t any compilation error, but the code makes no sense.

I changed to Types::Record, and solution (1) started to work. Learned something good, thank you, Martin~