web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

While Select statement and Containers

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    303,730 Super User 2026 Season 1 on at

    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);

    }

    }

  • Community Member Profile Picture
    on at

    Oh my god, I feel so dumb.

    Thanks!

  • Community Member Profile Picture
    on at

    I don't understand but where did the custTransCont come from?

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans