[AL] How to use user input from request page for report generation

DanHint
Member Posts: 3
Hey all,
I am completely new at AL programming and am doing a little testing in my business central sandbox.
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):
In my data item, I tried to use the following line to filter the data based on the user-chosen value:
I have searched the web for half an hour now and figured I might be faster just asking here.
I am completely new at AL programming and am doing a little testing in my business central sandbox.
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.
I have searched the web for half an hour now and figured I might be faster just asking here.
0
Best Answer
-
I solved it this way:
I created a trigger OnPreDataItem() in my Customer DataItem and inside the trigger I wroteif ChosenCust_Code <> '' then Cust.SetRange("No.", ChosenCust_Code);
0
Answers
-
If it's a field in the table then the user can simply set a filter on the field. You can use the RequestFilterFields property to define which fields are shown in the filter pane, and the user can then add more fields.
No need for a complicated variable trick.0 -
By the way, since it's a foreign key field, shouldn't you call it "Customer No."?0
-
More than 20 hours of development training, ALL for FREE!!!
https://www.youtube.com/embed/videoseries?list=PL1FESh9FqyhQxkZXYYp1X1tTpXf3-9iSR1 -
Thanks for your answer.
I just tried getting into variables and thus wanted to try this example.
Also if I was a user it would save me two clicks and some scrolling or searching.
So is there any way to properly pass user input to a query ("query" not meant in AL-syntax)?
The DataItemTableView is for the customer-table, so "No." is the field name. Or what did you mean by the foreign key "customer no."?0 -
I mentioned the RequestFilterFields property, which you can use to define fields that are shown in the filter pane by default. That'll save you two clicks, and a bunch of programming to filter on the field.
The way you explained it, I thought you had a table with a link to the customer number, so that's why I suggested the name.
You can create a field on the request page and set a variable as the source. Each control has triggers for OnValidate and OnLookup. You can program those to display the customer list and catch the record that the user selects. Then you can use the variable as the filter value in the dataitem trigger.0 -
I solved it this way:
I created a trigger OnPreDataItem() in my Customer DataItem and inside the trigger I wroteif ChosenCust_Code <> '' then Cust.SetRange("No.", ChosenCust_Code);
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions