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

Loop through selected records

(1) ShareShare
ReportReport
Posted on by 313
Hello everyone,
 
I found a lot of information online about how to loop through the selected records of a grid, but for some reason for me, it's only grabbing the last record I have selected.  I wanted to post my code and see if anyone notices something I'm doing wrong.
 
First, here is a print screen of the form I'm working on.  I pick the lines in the lower grid and then click Print Item Label which opens another form that should list the items selected so I can print labels
 
The datasource for the second grid is WMSArrivalDetailTmp
 
Here is my code that is running in the init method on the next form (for printing labels)
selectionHelper = MultiSelectionHelper::construct();selectionHelper.parmDatasource(element.args().record().dataSource());wmsArrivalDetailLoop = selectionHelper.getFirst();if (wmsArrivalDetailLoop.RecId){     while (wmsArrivalDetailLoop.RecId)     {          select salesLine               where salesLine.SalesId == wmsArrivalDetailLoop.InventTransRefId               && salesLine.ItemId == wmsArrivalDetailLoop.ItemId          join inventDim               where inventDim.inventDimId == salesLine.InventDimId;          if (salesLine)          {               table.ItemId = salesLine.ItemId;               table.Name = salesLine.Name;               table.TCI_UserID = curUserId();               table.TCI_Warehouse = inventDim.InventLocationId;               table.TCI_Location = inventDim.wmsLocationId;               table.NumOfLabels = abs(salesLine.ExpectedRetQty);               table.insert();          }               wmsArrivalDetailLoop = selectionHelper.getNext();     }}
 
I have the same question (0)
  • Andrew Huisman Profile Picture
    313 on at
    I'll repost the code to make it readable
     
    selectionHelper = MultiSelectionHelper::construct();
    selectionHelper.parmDatasource(element.args().record().dataSource());
    wmsArrivalDetailLoop = selectionHelper.getFirst();
    
    if (wmsArrivalDetailLoop.RecId)
    {
         while (wmsArrivalDetailLoop.RecId)     
         {
              select salesLine
                   where salesLine.SalesId == wmsArrivalDetailLoop.InventTransRefId
                   && salesLine.ItemId == wmsArrivalDetailLoop.ItemId
              join inventDim
                   where inventDim.inventDimId == salesLine.InventDimId;
    
              if (salesLine)
              {
                   table.ItemId = salesLine.ItemId;
                   table.Name = salesLine.Name;
                   table.TCI_UserID = curUserId();
                   table.TCI_Warehouse = inventDim.InventLocationId;
                   table.TCI_Location = inventDim.wmsLocationId;
                   table.NumOfLabels = abs(salesLine.ExpectedRetQty);
                   table.insert();
              }
                   
              wmsArrivalDetailLoop = selectionHelper.getNext();
         }
    }
     
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    Your code returns selected records and your screenshot shows a single selected record, therefore the result is correct.
     
    But selected records apparently isn't what you want. You want records with a particular value of Select of arrival column. To know how to implement it, you need to find out the data source of the column. If it's a table field, you can simply use a query. It may also be, say, an edit method backed by a collection (e.g. Set class). In that case, you need to simply iterate the collection.
  • Suggested answer
    Andrew Huisman Profile Picture
    313 on at
    Martin,
     
    Again, you have come to my rescue.  I figured it was something simple like this.  Thank you so much.
     
    For anyone who wants to know, here is my code now and it's working perfectly
     
    while select wmsArrivalDetailTmp
                    where wmsArrivalDetailTmp.Selected == NoYes::Yes
                {
                    select salesLine
                            where salesLine.SalesId == wmsArrivalDetailTmp.InventTransRefId
                            && salesLine.ItemId == wmsArrivalDetailTmp.ItemId
                        join inventDim
                            where inventDim.inventDimId == salesLine.InventDimId;
    
                    if (salesLine)
                    {
                        table.ItemId = salesLine.ItemId;
                        table.Name = salesLine.Name;
                        table.TCI_UserID = curUserId();
                        table.TCI_Warehouse = inventDim.InventLocationId;
                        table.TCI_Location = inventDim.wmsLocationId;
                        table.NumOfLabels = abs(salesLine.ExpectedRetQty);
                        table.insert();
                    }
                }
     

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans