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

Notifications

Announcements

No record found.

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
    301,037 Super User 2025 Season 2 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
    237,898 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans