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

  • Berthil Profile Picture
    204 on at
    RE: Can't seem to loop through datasource

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

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,330 on at
    RE: Can't seem to loop through datasource

    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.

  • Martin Dráb Profile Picture
    232,879 Most Valuable Professional on at
    RE: Can't seem to loop through datasource

    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.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Can't seem to loop through datasource

    Try this instead for the info part  -

    info(strFmt(loop.ItemId));

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,137 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,879 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans