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, ...
Suggested Answer

"Nested data access loop" warning

(1) ShareShare
ReportReport
Posted on by 1,967
Hi,

I'm getting nested data access loop warning. The code is working as expected but how can i change it to remove the nested loop?

       List orders = new List(Types::Class); 
       
        while select FieldA, FieldB from TableA
            group by TableA.FieldA, TableA.FieldB, salesLine.ReferenceField, salesLine.SalesId 
            where TableA.FieldA == "123"
              && TableA.FieldB == "ABC"
       join sum(FieldC) from TableB 
           where TableB.RefId == TableA.RecId
       join RecId from TableC
           where TableC.LinkId == TableA.LinkId
       join ReferenceField, SalesId from salesLine
           where salesLine.LinkId == TableC.LinkId
             && salesLine.Number1 != ''
             && salesLine.Id1 != ''
        {
            Contract contract = new contract();
            List x = new List(Types::Class);

            contract.parmNumber1(salesLine.Number1);
            contract.parmLineAmount(projInvoiceItemDetail.LineAmount);

            SalesLine salesLineLocal;
            while select Id1,Id2 from salesLineLocal
                    group by Id1, Id2
                    where salesLineLocal.SalesId == salesLine.SalesId
                        && salesLineLocal.Number1 == salesLine.Number1
            {
                if(SetupTable::Exists(salesLineLocal.Id1 salesLineLocal.Id2))
                {
                    x.addEnd(this.populateR(salesLineLocal.Id1, salesLineLocal.Id2));
                }
            }

            contract.parmR(x);

            orders.addEnd(contract);

        }

private List populateR(Id1 _Id1, Id2 _Id2)
{
    List y =  new List(Types::Class);

    Class1 class1 = new Class1();
    class1 = SetupTable::getSetup(_Id1, _Id2);

    y.addEnd(class1);

    return y;
}
 
Categories:
I have the same question (0)
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,527 Super User 2025 Season 2 on at
    I think You're getting the nested data access loop warning because of the inner while select loop inside your outer while select.
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Martin Dráb Profile Picture
    237,953 Most Valuable Professional on at
    The warning is indeed about the nested while selects. If you can replace it with a join, the result will be much more efficient. It's not always possible (and you can suppress the warning in such cases).
     
    What you definitely can improve is replacing the call of SetupTable::exists() with a join. It'll decrease the number of database calls by the number of records returned by the outer loop (if I disregard caching).
     
    I can't comment on methods like getSetup(), because I have no information about your code there.
     
    By the way, are you sure that the list in populateR() makes sense? It creates a new list every time containing exactly one element. The list x is then a collection of such one-element lists. Isn't it easier and more efficient to return class1 from populateR()?

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 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans