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)

Use AOT query in x++

(0) ShareShare
ReportReport
Posted on by 1,699

I created a query in the AOT. Now i want to use this query in x++ code but without writing the code for the datasource(s) incl. Joins (inner, outer), ranges, etc. again.

I was able to set the query:
query = new Query(queryStr(MyAOTQuery));

but i don't want to set the datasource again:
queryDs = query.dataSourceTable(tablenum(MyAOTTable));

because it's already defined in the AOT query. I'm just looking for a way to read the complete AOT query in x++ to use it.

Any ideas how to set this up?

Martin

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    Re: Use AOT query in x++

    It's not clear what you want to do with the query.
    You can simply create a QueryRun instance and run your query:

    QueryRun qr = new QueryRun(query);
    MyAOTTable myTable;
    while (qr.next())
    {
        myTable = qr.get(tableNum(MyAOTTable));
    }

    By the way, dataSourceTable() in your code doesn't create a new datasource, it reads the one you defined in AOT. You would add new datasource by calling addDataSource().

  • AXT Profile Picture
    1,699 on at
    Re: Use AOT query in x++

    Martin,

    Thanks for your answer. What i still do not understand is why i have to specify the table name:

    MyAOTTable myTable
    tableNum(MyAOTTable)

    When i create a new QueryRun instance i'm already referring to the query that exists in the AOT. So why AX does not know the datasource?

  • Verified answer
    Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    Re: Use AOT query in x++

    OK, you could also call myTable = qr.getNo(1); to get the record by datasource index instead of table ID. But I prefer the first approach.

    myTable variable is necessary to cast Common (return type of both get()/getNo()) to your table, so you can use fields etc. It the same thing as if you have a method returning Object instance, but you know what the real type is so you cast that object to the proper type.

    If you don't need the casting (because you just want to send the record to another process or to save its RecId), you can avoid the myTable variable. But that's not a common case.

  • AXT Profile Picture
    1,699 on at
    Re: Use AOT query in x++

    Thanks, very good answer

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

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
NNaumenko Profile Picture

NNaumenko 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans