web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Warning Nested data access loop found in Method

(0) ShareShare
ReportReport
Posted on by 6

  while select AccountNum, TransDate,AmountMST,Invoice from vendTrans /*group by vendTrans.AccountNum*/ where vendTrans.TransDate==fromdate
        {
            select AccountNum ,party from vendTable where vendTable.AccountNum==vendTrans.AccountNum
                    join Name,RecId from partyTable where partyTable.RecId==vendTable.Party
                    join Locator from logisticsElectronicAddress where logisticsElectronicAddress.RecId==partyTable.PrimaryContactEmail;
            str emails = logisticsElectronicAddress.Locator;
            SysMailerMessageBuilder mailer = new SysMailerMessageBuilder();
            mailer.setFrom(EmailParameters.SMTPUserName);
            mailer.addTo(emails);
            mailer.setSubject(strFmt(" Payment Details - %1 %2",vendTable.AccountNum,partyTable.Name));
            body = "Hi Dear "   strFmt(" %1 

Vendor Account No. : %2
",partyTable.Name,vendTable.AccountNum);             body = strFmt("
We have Paid for the amount of INR : %1 /-

Please find below invoice wise details for this payment done on : %2 

",vendTrans.AmountMST, vendTrans.TransDate);               while select  AccountNum,TransDate,SettleAmountMST from vendSettlement                  where vendSettlement.TransRecId==vendTrans.RecId             {                 body = strFmt("

External Document No. %1  Invoice Amount : %2 /-  
",vendtrans.Invoice, vendSettlement.SettleAmountMST);             }             //body = "Hi, " strFmt(" Dear %1,  

We have Paid for the amount of INR : %2 /-
Please find below invoice wise details for this payment done on : %3 


External Document No. %4  Invoice Amount : %5 /-  

We Thankyou for choosing Bisleri and take pride in having you as our partner.
Assuring you of our Best services at all times


",partyTable.Name,vendTrans.AmountMST,vendTrans.TransDate);//,vendTrans.Invoice,vendSettlement.SettleAmountMST)  ;             body = strFmt("

We Thankyou for choosing and take pride in having you as our partner.
Assuring you of our Best services at all times


");             localAccount = vendTable.AccountNum;             mailer.setBody(body,true) ;             SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(mailer.getMessage()) ;         }

pastedimage1672722627223v1.pngthe second while is used to printing multiple invoice amounts and invoice numbers like this, so how can this error be removed. Please help or optimize code so it can be removed Thankyouuuuupastedimage1672722325698v1.png

I have the same question (0)
  • Martin Dráb Profile Picture
    239,670 Most Valuable Professional on at

    First of all, let me remove code irrelevant to the problem, so we can focus on queries, and format code correctly.

    while select AccountNum, TransDate, AmountMST, Invoice from vendTrans
    	where vendTrans.TransDate == fromDate
    {
    	select AccountNum, Party from vendTable
    		where vendTable.AccountNum == vendTrans.AccountNum
    		join Name from partyTable
    			where partyTable.RecId == vendTable.Party
    		join Locator from logisticsElectronicAddress
    			where logisticsElectronicAddress.RecId == partyTable.PrimaryContactEmail;
    
    	while select AccountNum, TransDate, SettleAmountMST from vendSettlement
    	    where vendSettlement.TransRecId == vendTrans.RecId
    	{
    		// ...
    	}
    }

    Then we use a join instead of the first nested selected statement:

    while select AccountNum, TransDate, AmountMST, Invoice, RecId from vendTrans
    	where vendTrans.TransDate == fromDate
    	join AccountNum, Party from vendTable
    		where vendTable.AccountNum == vendTrans.AccountNum
    		join Name from partyTable
    			where partyTable.RecId == vendTable.Party
    		join Locator from logisticsElectronicAddress
    			where logisticsElectronicAddress.RecId == partyTable.PrimaryContactEmail;
    {
    	while select AccountNum, TransDate, SettleAmountMST from vendSettlement
    		where vendSettlement.TransRecId == vendTrans.RecId
    	{
    		// ...
    	}
    }

    Now the question is what to do with the nested while select. And to be honest, I would leave it there - I'm not convinced that getting rid of it would be better. But I would extract it to a separate method.

    By the way, I see you ignore improvements that I made to your code in your previous thread. :-(

  • GirishS Profile Picture
    27,843 Moderator on at

    Hi sachin mittal,

    You have used while select statement inside the while select. Thats why its throwing warning as nested while loop.

    You need to change the logic.

    On line number 14 - Do you need another while select from vendSettlement table?

    What is the purpose of that while select statement?

    Thanks,

    Girish S.

  • Sachin Mittal Profile Picture
    6 on at

    No I had added improvements added by you, and my issue was also resolved

    thankyou

  • Sachin Mittal Profile Picture
    6 on at

    this another while us needed to fetch multiple invoice number(external document number) and settlement amount for that account number that's need to be printed multiple times as in front end ,  have added a screenshot as well of that mail

  • GirishS Profile Picture
    27,843 Moderator on at

    So, it must be while select statement to retrieve multiple invoice numbers and settlements.

    In that case as martin suggested, better you leave it as it is. I don't think there will be any other way to solve this.

    Also, I have seen some standard code having nested while select. So, it's better to keep as it is.

    Thanks,

    Girish S.

  • Sachin Mittal Profile Picture
    6 on at

    so there is no any way to remove 'Warning Nested data access loop found in Method' this warning , as we have to left with no BP errors

    thankyou

  • GirishS Profile Picture
    27,843 Moderator on at

    No, you can't say like that in the general.

    For your scenario fixing nested while loop is not possible based on your functionality.

    So, it depends on the situation and functionality to solve nested while loops.

    Thanks,

    Girish S.

  • Sachin Mittal Profile Picture
    6 on at

    yes, actually I am also saying this for my functionality. Not generalizing for its removal

    thankyou

  • Martin Dráb Profile Picture
    239,670 Most Valuable Professional on at

    The BP warning won't be shown if you follow my suggestion and put the inner while select statement to a separate method.

    By code improvements, I meant remiving unnecessary fields from field lists, using correct line indentation, simplifying code for sending the email and so on.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 635 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 595 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 557

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans