Request Form Global Variable

infonoteinfonote Member Posts: 233
Hi,

How can I assign a global variable to a request form so I can then use the value in the variable in a setfilter?

In the request form of a report, I have added a textbox in which the user enter a value.

The value is then used for filtering.

Thanks in advance,

Comments

  • garakgarak Member Posts: 3,263
    make a global variable (MYGLOBALVAR). Then give your textbox (or other control from toolbox) the property [SourceExpr] -> MYGLOBALVAR.

    In your DataItem in trigger DataItem - OnPreDataItem(), you can use your global variable as filtercriteria. For example:
    ....
    DataItem.setfilter(FieldToFilter,MYGLOBALVAR);
    ....
    

    Regards
    Do you make it right, it works too!
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    It is simply straight forward :o

    1) Declare a global var
    2) Make it source expression of the textBox in request form.
    3) Use this var to filter anywhere in the report.

    RecVar.setrange(RecVarField,yourGlobalVariable); OR
    ...........setfilter....................................................OR
    anyway you want the value in the global variable. It is available to report's all dataItems and corresponding triggers


    I hope it helps. O:)
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DosihrisDosihris Member Posts: 23
    Hi,

    i have the same problem, but i'm a beginner, so can you explain this a little bit? I have a form and there you can select a date. when i print the record (the code to print this record is in the table in the PrintRecord trigger), i want to make a selection before i print that depends on this date. so do i have to declare a global variable in the table or in the form??? how can i access one of this variable from the other place?
  • garakgarak Member Posts: 3,263
    You call from the "Print" Button on your form (is this a form based on a table or with oout a SourceTable ?) the "PRINTRecord" function. Is this a self made function or the standardfunction for example in table 112). If it is your own, you can add a parameter. If it is the standardfunction, you can create a new one in the table with a parameter and set there your global Parameter.

    But first: is this a form based on a table (f.ex. 112) or without a SourceTable ?

    Regards
    Do you make it right, it works too!
  • DosihrisDosihris Member Posts: 23
    my form is based on a table. Thats the reason why the code to print the report is in the PrintRecord-Trigger of the table...
  • garakgarak Member Posts: 3,263
    which table? Sales Invoice Header?

    So, i think your source behind the Button looks like this (example use SalesInvHeader):
    CurrForm.SETSELECTIONFILTER(SalesInvHeader);
    SalesInvHeader.PrintRecords(TRUE); //or false
    

    The Code in PrintRecords() looks like this (it's standard)
    WITH SalesInvHeader DO BEGIN
      COPY(Rec);
      FIND('-');
      ......
      ......
      ReportSelection.SETFILTER("Report ID",'<>0');
      ReportSelection.FIND('-');
      REPEAT
        REPORT.RUNMODAL(ReportSelection."Report ID",ShowRequestForm,FALSE,SalesInvHeader);
      UNTIL ReportSelection.NEXT = 0;
    END;
    

    So you see, there is a copy function on a new Instance of the (here) SalesInvHeader. These Copy() function copies also all filters of the current REC (where yout form is based). So if you set a filter before your PrintRecord() command like
    SalesInvHeader.setrange("Posting Date",060108D); //or  datevariable
    SalesInvHeader.PrintRecords(true); //or false
    SalesInvHeader.setrange("Posting Date");
    

    The report will print the Recs with this "Posting Date". But if no rec exist with your posting Date, a error pops up in function PrintRecords() (find('-'))

    Also you can create a new function in your table like SetPrintParameters(Parameters) and these parameters you use as a global Variable in the PrintRecords() function. But also here: If no recs exist, the find('-') brings an error:
    //new function SetPrintParameters in table
    
    SetPrintParameters(Para1,Para2,Parax)
    GlobVar1 := Para1;
    GlobVar2 := Para2;
    GlobVarX := ParaX;
    
    ..........
    ..........
    
    //the modified PrintRecords function look now like this
    
    WITH SalesInvHeader DO BEGIN
      COPY(Rec);
      
      //new code +++++
      setfilter(SomeField1,GlobalVar1);
      setfilter(SomeField2,GlobalVar2);
      //new code --------
    
      FIND('-');
      ......
      ......
      ReportSelection.SETFILTER("Report ID",'<>0');
      ReportSelection.FIND('-');
      REPEAT
        REPORT.RUNMODAL(ReportSelection."Report ID",ShowRequestForm,FALSE,SalesInvHeader);
      UNTIL ReportSelection.NEXT = 0;
    END;
    
    //The Code behind your Print Button
    .......
    .......
    SalesInvHeader.SetPrintParameters(Para1,Para2,Parax);
    SalesInvHeader.PrintRecords(TRUE);
    

    For more help, it's helpfully to see a codesnippes or the for self (picture)

    Regards
    Do you make it right, it works too!
  • DosihrisDosihris Member Posts: 23
    Hey Grak,

    that was the most helpful post i read. I did it with a new function on the table and used the global varaibles. So it works... Thank you.

    Happy new year

    Nico
  • garakgarak Member Posts: 3,263
    Please and happy new year (frohes neues jahr)
    Do you make it right, it works too!
Sign In or Register to comment.