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

Query fails and returns every record in tables

(0) ShareShare
ReportReport
Posted on by 10

A customer could suddenly not open the form Settle Open Transactions (VendOpenTrans) and the system would lock up. I looked at the query for the main datasource and when I rebuilt it in a job I got the same result.

The query with parts commented out will work and return records for the Party ID 5637155687 - VendTransOpen joined with VendTrans joined with VendTable:

qvto = query.addDataSource(tableNum(VendTransOpen));

qvtr = qvto.addDataSource(tableNum(VendTrans));
qvtr.addLink(fieldNum(VendTransOpen, AccountNum), fieldNum(VendTrans, AccountNum));
qvtr.addLink(fieldNum(VendTransOpen, RefRecId), fieldNum(VendTrans, RecId));
qvtr.addRange(fieldNum(VendTrans, Approved)).value(queryValue(1));

//qhw = qvtr.addDataSource(tableNum(HcmWorker));

//qhw.addLink(fieldNum(VendTrans, Approver), fieldNum(HcmWorker, RecId));

//qhw.joinMode(JoinMode::OuterJoin);
//qll = qvtr.addDataSource(tableNum(LogisticsLocation));
//qll.joinMode(JoinMode::OuterJoin);
//qll.addLink(fieldNum(VendTrans, RemittanceLocation), fieldNum(LogisticsLocation, RecId));
qvt1 = qvtr.addDataSource(tableNum(VendTable));

qvt1.addLink(fieldNum(VendTrans, AccountNum), fieldNum(VendTable, AccountNum));
qvt1.addRange(fieldNum(VendTable, Party)).value(queryValue(5637155687));
//qvt = qvto.addDataSource(tableNum(VendTable));
//qvt.addLink(fieldNum(VendTransOpen, AccountNum), fieldNum(VendTable, AccountNum));
//qdim = qvto.addDataSource(tableNum(DimensionAttributeValueCombination));
//qdim.joinMode(JoinMode::OuterJoin);
//qdim.addLink(fieldNum(VendTransOpen, CashDiscountLedgerDimension), fieldNum(DimensionAttributeValueCombination, RecId));

If I add ANY of the other datasources I will get every record with every join added - too much data to handle...

In debug I see VendTransOpen_q query forming as expected and as soon as one of the others are added it only shows "Query object" with no info in debugger. Any ideas on the source of this issue?

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi nmkloster,

    I guess your query is not designed correctly, as you join quite a lot of data sources to the same data source and the query doesn't work well if you don't fetch mode or don't use the parent data source parameter in addLink method. If you want to reproduce the issue, just write it in x++ with built-in SQL syntax.

    If something suddenly stopped working, it could be new customization deployed recently to the environment or something wrong with SQL server. Do you perform any kind of DB maintenance?

    I recommend you to open SQL server management studio and connected to SQL DB used for the environment, and start SQL server activity monitor. Then try to open the form again and check the query you catch from Current Expensive Queries. Most likely you need to rebuild indexes for the tables above or maybe there is a missing index.

    www.sqlshack.com/.../

  • nmkloster Profile Picture
    10 on at

    The same query written out as "select VendTransOpen join..." works fine. Index' should be rebuilt regularly but someone else is looking into that and will be trying to monitor SQL server and call the form.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    As Sergei pointed out, your Query object is not the same query as "select VendTransOpen join...". Otherwise you would get the same results. You can check the actual query for both scenarios in SQL Server Activity Monitor.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans