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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

how to get field dynamics query parameter outside while loop

(0) ShareShare
ReportReport
Posted on by 69

I have calculated opening balance of customer successfully in highlited code but opening balance populates with every row... i want to calculate opening balance of customer outside of the while loop how can i get accountnum field while it is selected dynamically in query parameter. my code is as below and my contract class has only two parameters from date and to date .

queryRun = new QueryRun(query);

while(queryRun.next())
{
tmpTable.clear();

custTable = queryRun.get(tableNum(CustTable));
custTrans = queryRun.get(tableNum(custTrans));
custInvoiceTrans = queryRun.get(tableNum(CustInvoiceTrans));

tmpTable.AccountNum = custTable.AccountNum;
tmpTable.CustName = custTable.name();
tmpTable.Address = custTable.address();
tmpTable.TransDate = custTrans.TransDate;
tmpTable.Description = custTrans.Txt;
tmpTable.Debit = custTrans.AmountMST > 0 ? custTrans.AmountMST : 0;
tmpTable.Credit = custTrans.AmountMST < 0 ? abs(custTrans.AmountMST) : 0;
tmpTable.Voucher = custTrans.Voucher;
tmpTable.InvoiceId = custTrans.Invoice;
tmpTable.ItemId = custInvoiceTrans.ItemId;
tmpTable.Name = custInvoiceTrans.Name;
tmpTable.Qty = custInvoiceTrans.Qty;
tmpTable.SalesPrice = custInvoiceTrans.SalesPrice;

TmpTable.OpeningBalance = this.CalcOpening(custTable.AccountNum,contract.parmDateFrom());

tmpTable.insert();

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Satish Panwar Profile Picture
    14,673 Moderator on at

    Hi Mahmood,

    While there may be multiple options, one option is to run your calculateBalance option once by just adding another variable for custAccount and use that for comparison. Use order by as well in query.

    CustTable refCusTable

    Initialize this in end of loop, then use for comparison with next record...if same skip the loop. This will make sure only first record has balance.

    Another option is create another table that only holds customer and balance column.

    Thanks,

    Satish Panwar

    Please take time to click yes against the answer that help guide you in right direction.

  • Mahmood Ul Hassan Profile Picture
    69 on at

    Satish Panwar can you please guide me with code sample ?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans