Announcements
Is there any way Containers can be used in a while select statement? This is what I want to achieve:
Container Items;
PurchLine purchLine;
int i;
;
Items = [9109-0018,9109-0019,9109-0022,9109-0025];
for (i=1; i <= conlen(Items); i++)
{
while select PurchId from purchLine
where purchLine.ItemId == conpeek(custTransCont, i)
{
info(purchLine.PurchId);
}
}
But AX won't let me compare the value grabbed from conpeek. I guess it cannot... but wondering if you gents got any solution for it? Maybe I am not thinking it through
*This post is locked for comments
Note that the code is quite inefficient, because it executes a database query for each item in the container. A better approach would be constructing a query with several ranges and running it once. Like this:
Query q = new Query(); QueryRun qr; QueryBuildDataSource ds = q.addDataSource(tableNum(PurchLine)); ds.addSelectionField(fieldNum(PurchLine, PurchId)); for (i = 1; i <= conlen(items); i++) { itemId = conpeek(items, i); ds.addRange(fieldNum(PurchLine, ItemId).value(queryValue(itemId)); } qr = new QueryRun(q); while (qr.next()) { PurchLine purchLine = qr.get(tableNum(PurchLine)); info(purchLine.PurchId); }
By the way, I would avoid containers unless there is a good reason for using them. A set of strings would be a good alternative in this case.
I don't understand but where did the custTransCont come from?
Oh my god, I feel so dumb.
Thanks!
Hi Khosla,
You can create a variable where you first store the Item from the container. This variable can be used in the select statement as workaround, so try this:
Container Items;
PurchLine purchLine;
ItemId itemId;
int i;
;
Items = [9109-0018,9109-0019,9109-0022,9109-0025];
for (i=1; i <= conlen(Items); i++)
{
itemId = conpeek(custTransCont, i);
while select PurchId from purchLine
where purchLine.ItemId == itemId
{
info(purchLine.PurchId);
}
}
André Arnaud de Cal...
294,217
Super User 2025 Season 1
Martin Dráb
232,978
Most Valuable Professional
nmaenpaa
101,158
Moderator