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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create query in X++

(0) ShareShare
ReportReport
Posted on by 107

Hi guys,

I am trying to build a query in X++ but i can't seem to do it right.

Example:

Table 1

Table 2 => Has a relation with Table 1

Table 3 => Has a relation with Table 1

My code:

Query query = new Query();

QueryBuildDatasource qbds1, qbds2, qbds3;

qbds1 = query.addDatasource(tableNum(Table1));

qbds2 = qbds1.addDatasource(tableNum(Table2));

qbds2.relation(true);

qbds3 = qbds1.addDatasource(tableNum(Table3));

qbds3.relations(true);

Now my problem:

Adding Table1 => Ok, in debugger i can see query object as "Query object 2c70e208: SELECT * FROM Table1(Table1_1)"

Adding Table2 => Ok, in debugger i can see query object as "Query object 2c70e208: SELECT * FROM Table1(Table1_1) JOIN * FROM Table2(Table2_1) ON Table1.Id = Table2.Id"

Adding Table3 => NOK, the query object looks to be broken and in the debugger it gets the following value "Query object 2c70e208"

When i write the query in a select statement, in SQL or build it in a AOT query there is no problem and i get the results correctly.

Does anyone have an idea what's wrong?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Create query in X++

    You should distinguish between what you see in debugger and whether the query works (which should still be the case).

    In general, QueryBuildDataSource.toString() (which is also what you see in debugger) doesn't work very well with queries with several branches.

    You can change the structure of your query:

    From:
    T1 -> T2
       -> T2
    To something like: T2 -> T1 -> T3

    Alternatively, setting fetch mode to One2One (on both child data sources) should fix it too.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Create query in X++

    Try setting .fetchMode(QueryFetchMode::One2One);

    Some additional details:

    [View:http://dynamicsaxhints.blogspot.hu/2015/11/query-datasource-fetchmode-property.html:750:50]

    [View:http://www.to-increase.com/ax-fetch-mode/:750:50]

  • BuBbA Profile Picture
    107 on at
    RE: Create query in X++

    Thanks guys, that was very quick! Adding the fetch mode to the query solved it for me!

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans