[AL] filter reports by user-input-variables

Hey all,

I am new to AL and Business Central and am trying stuff out in my Sandbox - currently reports.
On my report’s request page I would like to add a field in which I can choose a customer and then only show data for the chosen customer in the report.
I have successfully added the field but fail to properly configure the DataItemTableView, so the data passed to the report layout is pre-filtered.

This is the field I added (“ChosenCust_Code” is the variable I want to store my user-chosen value in):

field(ChosenCust; ChosenCust_Code)
                        Caption = 'Customer to notify:';
                        ToolTip = 'Specifies the customer to create the overdue notice for.';
                        ApplicationArea = All;
                        TableRelation = Customer."No.";

In my data item, I tried to use the following line to filter the data based on the user-chosen value:

DataItemTableView = where("No." = const(ChosenCust_Code));

“No.” is the field in my data item table (PK) which should align with the ChosenCust_Code variable.
My main goal is to properly filter the information before passing it to the layout (so I only have to do some sums and grouping in Report Builder).

I solved it by creating a OnPreDataItem() trigger in my Customer DataItem and inside used

if ChosenCust_Code <> ‘’ then Cust.SetRange(“No.”, ChosenCust_Code);