OnInit Report - Need Help

SteffenW
Member Posts: 3
Hello there,
I have an Report, which need an "OnInit Report - Trigger".
The Trigger looks like:
IF Rezeptzähler.Nr >= 99700
THEN
MESSAGE ('Bitte Info an die IT!');
But in my Report the "OnInit Report" do not have the Value from my Table "Rezeptzähler".
The Report get the Number when i print it, but then it is to late..
Can somone please tell me, how the Report get the Value from the Table, when the Report is opened?
Thank you!
Best wishes
Steffen
I have an Report, which need an "OnInit Report - Trigger".
The Trigger looks like:
IF Rezeptzähler.Nr >= 99700
THEN
MESSAGE ('Bitte Info an die IT!');
But in my Report the "OnInit Report" do not have the Value from my Table "Rezeptzähler".
The Report get the Number when i print it, but then it is to late..

Can somone please tell me, how the Report get the Value from the Table, when the Report is opened?
Thank you!
Best wishes
Steffen
0
Answers
-
OnInit is called when an instance of object is created in memory. At this point the report "does not know" about filters or data int the table.
The first time the report "sees" the data in the table is in OnAfterGetRecord.
Filter however are setup in OnPreDataItem, so you can add a FINDSET to OnPreDataItem to prefetch the record if you need your data earlier.
If you need to have some data available earlier than that you need to created a function on the report, create report variable and create that function to pass required data before calling ReportVar.RUN()
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Thank you very much for that Info.
But i did not completly understand how I do that..
My table called „Rezeptzähler“ and the Field I need called „Nr“. So what is the code I put in my „OnInit Report“? So that the Report will Show a Message if the Field „Nr“ in the Table „Rezeptzähler“ is bigger than 99700?
Thanks0 -
OK sorry, I misunderstood your question
In the report create a table variable of the same type as your data item (Rezeptzähler)
Then in In OnPreDataItem do this:RezeptzählerCopy.COPY(Rezeptzähler) RezeptzählerCopy.SETFILTER(Nr, '>=%1', 99700); IF NOT RezeptzählerCopy.ISEMPTY THEN ERROR('Bitte Info an die IT!');
Note: If you use MESSAGE the system will show the message and will print the report anyway - regardless where you put your code. If you want to prevent the report from being printed you need to use the ERROR in OnPreDataItem.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03-1 -
Create a global function in your report then call the function to pass parameter (Rec) before running the report. Then you can use FINDSET or GET function to fetch the value at OnInit trigger.
Thanks0 -
Thank you Slawek and Thank you wolfskin!
I made it like wolfskin said, and it works great!
I have now an Variable called "RezeptzählerRec" and in my "OnInitReport" is the following Code:RezeptzählerRec.SETFILTER(Nr, '>99700'); IF RezeptzählerRec.FINDSET THEN MESSAGE('Bitte Info an die IT!'); RezeptzählerRec.SETFILTER(Nr, '99999'); IF RezeptzählerRec.FINDSET THEN ERROR('Info an die IT!');
The Report will now show the Message "Bitte Info an die IT", and when it is on 99999 then The Error will show up and the Report can not be oben.
Thank you very much!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