OnInit Report - Need Help

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.. :expressionless:

Can somone please tell me, how the Report get the Value from the Table, when the Report is opened?

Thank you!

Best wishes
Steffen

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    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-03
  • SteffenWSteffenW Member Posts: 3
    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?

    Thanks
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    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
  • wolfskinwolfskin Member Posts: 84
    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.

    Thanks
  • SteffenWSteffenW Member Posts: 3
    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!
Sign In or Register to comment.