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

How To speed Up Nested Loop

(0) ShareShare
ReportReport
Posted on by 77

Hi Guys,

i Have a request that User Enter one Warehouse and many Locations
 i handled the location by multiSelect
then i insert in Table Items that meets this criteria with the rest of inventDim combination

for example use choose Warehouse " X " Locations " Y,Z,N".

i must meet this criteria to find the item with the rest of inventory dimensions like Pallet,InventoryStatus,Serial Number etc..
so one item can have multiple records and the same for other items

so i made nested loop for all required dimensions and i use InventDim::FindOrCreate(myCombination) For each loop

but it takes alot of time .. can anyone help ?

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: How To speed Up Nested Loop

    Nested loops are usually a bad idea because they are slow. You should implement similar functionality as a single loop (for example by using joins) instead. 

    This is a general answer to your general question. 

  • Verified answer
    Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: How To speed Up Nested Loop

    Does it mean that you're trying to find all InventDim records for the given warehouse and locations? It surely can be done by a single query.

    If you wrote a select statement, you would do something like

    where Warehouse == "X" and (Location == "Y" or Location = "Z" or ...)

    To do dynamically, you need to use Query* classes . For example:

    Query query = new Query();
    QueryBuildDataSource ds = query.addDataSource(tableNum(InventDim));
    ds.addRange(fieldNum(InventDim, InventLocationId)).value(queryValue('X'));
    ds.addRange(fieldNum(InventDim, wmsLocationId)).value(queryValue('Y'));
    ds.addRange(fieldNum(InventDim, wmsLocationId)).value(queryValue('Z'));
    ds.addRange(fieldNum(InventDim, wmsLocationId)).value(queryValue('N'));

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans