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 :
Small and medium business | Business Central, N...
Suggested answer

Using a Query for Report with Temp Table

(0) ShareShare
ReportReport
Posted on by 3,197

Hi All

I'm trying to generate a report that reads from a temporary table. However, the temporary table should be populated from a Query when a user runs the report. So far no data pulls through (empty error).

I have used pattern from Dynamics 365 Business Central: Using the query as a data source for a page (Query.Open Method) | Dynamics 365 Lab (yzhums.com)

So far this is my code and I have tried triggers predataItem and onaftergetrecord:

            column(Lot; Lot) { }
            column(Serial; Serial) { }

            trigger OnPreDataItem()
            var
                LotByBinTemp: Record LotByBinTemp;
                LotByBinQuery: Query LotNumbersbyBin;
            begin
                LotByBinTemp.DeleteAll();
                if LotByBinQuery.Open() then begin
                    while LotByBinQuery.Read() do begin
                        LotByBinTemp.Init();
                        LotByBinTemp.RowNo := LotByBinTemp.RowNo   1;
                        LotByBinTemp.Location := LotByBinQuery.Location_Code;
                        LotByBinTemp.ItemNo := LotByBinQuery.Item_No;
                        LotByBinTemp.Lot := LotByBinQuery.Lot_No;
                        LotByBinTemp.Serial := LotByBinQuery.Serial_No;
                        LotByBinTemp.Insert();
                    end;
                    LotByBinQuery.Close();
                end;
            End;

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,045 Moderator on at
    RE: Using a Query for Report with Temp Table

    I wonder if you are filling your temp table too early in the process?

    What is the dataitem for your report?

    Maybe you can share more of the code?

  • M Saravanan Profile Picture
    242 on at
    RE: Using a Query for Report with Temp Table

    Dear Samantha,

    Have you succeded in meeting out the above requirement..? If so, please share the ways to achieve it..

    Thanks in advance,

    Saravanan M

  • Suggested answer
    Steven Renders Profile Picture
    5,672 Moderator on at
    RE: Using a Query for Report with Temp Table

    Here's an example:

    How Do I: Create a Report based upon a Query? – think about IT

    blog/ReportBasedOnQuery at master · srenders/blog · GitHub

  • Greg Kujawa Profile Picture
    519 on at
    Using a Query for Report with Temp Table
    I too was running into the same exact issue after following the instructions listed in that very helpful article you cited. I used the Page Inspector and could see the temp table rows were there. But the page itself was just blank. The issue for me was I forgot to include ApplicationArea = All for each field on the page. Easy fix. :) 

    And one other thing. Per that helpful article, the temp table needs to be populated in the OnOpenPage() trigger.

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 > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,750

#2
Sumit Singh Profile Picture

Sumit Singh 2,689

#3
YUN ZHU Profile Picture

YUN ZHU 1,987 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans