Search code examples
axaptadynamics-ax-2012x++

AOT query can reference a TempDB table as a data source


We use AX 2012 R3.

Temporary TempDB Tables [AX 2012] states that A query under AOT > Queries can reference a TempDB table as a data source.
My question: How does an AOT query read the records written into a data source that is a TempDB table?

The problem that I have is that the AOT query seems unable to read any record from my TempDB table data source:

I defined a TempDB table under AOT, and I also created an AOT query which references this TempDB table as a data source.
I write a method to fill out the TempDB table and then I write a while queryRun loop, passed with the AOT query object mentioned above. However, the loop body was never run.
I have made sure that the code is written correctly: if I changed the TempDB table into a Regular table, the loop body is entered and generates the results correctly.

(Alternatively, I have written a while select instead of the queryRun of the AOT query. The while select loop generates correct results, regardless of whether the joined table is TempDB or Regular. However, I want to allow adding other ranges. A while select loop seems not able to do this. So, I use a while queryRun loop following some SysQuery::findOrCreateRange.)

The link above also states that a TempDB table exists only during the scope of a method that instantiates it. The filling out of TempDB table and the loop that I wrote are done in the same method. But, as I never instantiate a table, what is meant by to instantiate it(a TempDB table)?

EDITs: 1) I also tried to write some code following the while queryRun loop to see if there are records in the TempDB table, and found that the records are still present in the TempDB table. 2) To clarify, a while queryRun loop means the following

QueryRun queryRun = new QueryRun(query);
while(queryRun.next()){...}

The query in the instantiation of queryRun above is an AOT query object.


Solution

  • After you fill the TempDb table you need to pass it to the query via queryRun.setRecord([TempDb Table])

    Then do your while(queryRun.next()){...}