Adding filters to report

HohenzollernHohenzollern Member Posts: 18
Hi to all,

Have some problems with creating of report. For example, have 2 tables - "Employee" and "Pers"(have some key fields from Employee).
Data from those tables have to be shown in report, on pressing special button, that is on the form.
I can set filter in such a way
Employee.SETRANGE("No.",Rec."Pers");
REPORT.RUN(REPORT::"Test Report",TRUE,FALSE,Employee);
But I don't know how to set several filters, executed on 1 REPORT.RUN.
Tell me please, where I can read or find an example of what I need.
I'm still learning, thx for any help)

Comments

  • geordiegeordie Member Posts: 655
    With this statement it's possible to manage only one record variable, you need to use a Report variable and pass the filters with a function:
    Employee.FILTERGROUP(10);
    Employee.SETRANGE("No.",Rec."Pers");
    Pers.FILTERGROUP(10);
    Pers.SETRANGE("Department",'IT');
    TestReportVar.SetFilters(Employee,Pers);
    TestReportVar.RUN;
    

    In SetFilter function remember to pass the parameter by value otherwise you'll have empty filters.
    Moreover choose a non-internally used filtergroup in order to combine your filters with DataItemLink property and set them in OnPreDataItem trigger:
    EmployeeFilters.FILTERGROUP(10);
    EmployeeDataItem.COPYFILTERS(EmployeeFilters);
    
  • HohenzollernHohenzollern Member Posts: 18
    Thx for anwer, if you don't mind, one more question:

    As I understand, I have to create function named "SetFilters", with record parameters "Employee" and "Pers". The code in it have to be
    Employee.FILTERGROUP(10);
    Employee.SETRANGE("No.",Rec."Pers");
    Pers.FILTERGROUP(10);
    Pers.SETRANGE("Department",'IT');
    

    It will be activated on the onRun trigger with
    TestReportVar.SetFilters(Employee,Pers);
    TestReportVar.RUN;
    

    Sorry if it's a stupid question, just want to make it all clear.
  • geordiegeordie Member Posts: 655
    Thx for anwer, if you don't mind, one more question:

    As I understand, I have to create function named "SetFilters", with record parameters "Employee" and "Pers". The code in it have to be
    Employee.FILTERGROUP(10);
    Employee.SETRANGE("No.",Rec."Pers");
    Pers.FILTERGROUP(10);
    Pers.SETRANGE("Department",'IT');
    

    Not exactly, in the function you just need to copy the filters applied in the calling object from parameters record variables to global variables in the report:
    EmployeeGlobal.COPYFILTERS(EmployeePar);
    PersGlobal.COPYFILTERS(PersPar);
    

    Which you will have to use in OnPreDataItem trigger.
  • HohenzollernHohenzollern Member Posts: 18
    seems to have understood, thx once again, have a nice day)
  • vaprogvaprog Member Posts: 1,141
    Hi Hohenzollern,

    geordie taught you a more advanced technique to pass parameters to a report. If you just want to set filters for dataitems in the report programmatically, you neither need to meddle with FILTERGROUP nor need to create a function in the report to pass the parameters. Instead you can do like this:
    Employee.RESET;
    Employee.SETRANGE("No.",Rec."Pers");
    TestReportVar.SETTABLEVIEW(Employee);
    Pers.RESET;
    Pers.SETRANGE("Department",'IT');
    TestReportVar.SETTABLEVIEW(Pers);
    TestReportVar.RUN;
    
    Done like this, the filters passed will be pre-populated in the request form, if you show it and the report is configured to accept user filter entries for the dataitem.

    I find geordie's use of FILTERGROUP somewhat confusing. Setting the filter group to 10 before the function is called will later hide the filters from the user (something you did not ask for and thus might be misleading). Within the function, setting FILTERGROUP does not have any effect in this case, as COPYFILTERS copies filters from all filter groups to the same filter group in the destination respectively. So, use of FILTERGROUP is optional.

    (SETTABLEVIEW, on the other hand, copies the filters from the current filter group only, but also sets the key, in the same way as
    EmployeeDataItem.SETVIEW(Employee.GETVIEW);
    would do.)
  • HohenzollernHohenzollern Member Posts: 18
    Hi, vaprog
    vaprog wrote:
    I find geordie's use of FILTERGROUP somewhat confusing. Setting the filter group to 10 before the function is called will later hide the filters from the user (something you did not ask for and thus might be misleading). Within the function, setting FILTERGROUP does not have any effect in this case, as COPYFILTERS copies filters from all filter groups to the same filter group in the destination respectively. So, use of FILTERGROUP is optional.

    As I write before, I'm still learning and usage of different functions sometimes isn't enough clear for me. Yesterday was the first time I saw FILTERGROUP) So you're right, that is the reason,why I didn't ask and that is misleading. But I have already read about, for example even there: http://www.mibuso.com/howtoinfo.asp?FileID=22

    I find your way more comfortable for me, cause for the time being I'm not an advanced developer but trying to become)

    Thx for both of your answers.
  • geordiegeordie Member Posts: 655
    vaprog wrote:
    Hi Hohenzollern,

    geordie taught you a more advanced technique to pass parameters to a report. If you just want to set filters for dataitems in the report programmatically, you neither need to meddle with FILTERGROUP nor need to create a function in the report to pass the parameters. Instead you can do like this:

    Yes, my fault because I wrongly remember some problems using SETTABLEVIEW for more than one dataitem when running a report :oops:
Sign In or Register to comment.