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 :
Finance | Project Operations, Human Resources, ...
Answered

Can't seem to loop through datasource

(0) ShareShare
ReportReport
Posted on by 204

Hi all,

I'm trying to create the following process:

2110.weightcheck.png

(1) Get packing lines and fill them in a temp table shown in a form

(2) Loop through records and calculate total weight when button is clicked

However if the button code below is executed it loops through the same amount of rows that is in the datasource but in my case the itemid is not updated. 

Any idea why?

void clicked()
{

    WHSTmpPackingLine loop = whstmppackingline_ds.getFirst();

    while (loop)
    {

        info(strFmt(WHSTmpPackingLine.ItemId));

        loop = WHSTmpPackingLine_ds.getNext();

    }

    super();
}

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Try this instead for the info part  -

    info(strFmt(loop.ItemId));

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    If it's a temporary table, you can simply use a select statement:

    while select whsTmpPackingLine
    {
        info(strFmt(whsTmpPackingLine.ItemId));
    }

    Or, if you want to take into account query ranges, you can use a query instead.

    Then you can also use sum() aggregation function to calculate the total.

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi Berthil,

    As mentioned by Gunjan, you need to use  info(strFmt(loop.ItemId));

    Also as a best practice do not use generic variables like 'loop' instead you can create variables like WHSTmpPackingLine whsTmpPackingLineloc = whstmppackingline_ds.getFirst(); and use whsTmpPackingLineloc in your logic. such code is more readable in the future by you or anyone else.

  • Berthil Profile Picture
    204 on at

    Thank you for your tip! I understand the logic now. I'm not much of a programmer and just conquering the concepts of X++.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans