Set a different filter on a Data Item when Run a report.

kirkostaskirkostas Member Posts: 127
I have a report with a Data Item on system table Date.
I have fill out the ReqFilterFields property to ask for "Period Start" filtering.
If you filter for '01/01/08..TODAY' the report works.
But if you filter for '01/01/08..' the report have to pass through all records from Date table and this is not good.

So, I have created a function which detect that you didn't gave the TO value and create a TO value using the TODAY function.

The problem is that I am trying to filter the Date table manually and I can't.

Here is the code:
{
Variables
DateFilter is a TEXT.
DateFilter2 is a DATE.
Date is the Date system table.
}

DateFilter := Date.GETFILTER("Period Start");
IF COPYSTR(DateFilter, STRLEN(DateFilter), STRLEN(DateFilter)) = '.' THEN BEGIN
  EVALUATE(DateFilter2, COPYSTR(DateFilter, 1, STRLEN(DateFilter)-2));
  Date.SETRANGE("Period Start", DateFilter2, TODAY);
END;

The report just ignore the SETRANGE and continue to run with the previous filter '01/01/08..'
Why?
kirkostas

Comments

  • kapamaroukapamarou Member Posts: 1,152
    You can get the filter bounds using GETRANGEMIN and GETRANGEMAX to see what the user entered. :D

    We will need to see more of your code and triggers to see what is wrong. If you debug your program what values does the filter have?
  • kirkostaskirkostas Member Posts: 127
    I have debug it and shows the correct range but when it runs it never ends.
    I tried to reset it, nothing.
    I tried to use a different variable for the Date table and then COPYFILTERS from it, nothing.

    If I enter it correct from the begging it works.

    ](*,)
    kirkostas
  • kapamaroukapamarou Member Posts: 1,152
    It could be that your code is in the wrong trigger.. Can you show us where your code is?

    You need to get the field filters in the OnPreReport trigger (keep them in variables) and then apply your actual filters in the OnPreDataitem trigger... I think that filters applied in the onprereport trigger are reset to user's choice after that trigger. So where is your code :?:
  • kirkostaskirkostas Member Posts: 127
    My code is on Report - OnPreReport trigger.
    And I use the GetFilters exactly after the SETRANGE to see if the filter is ok, and it is.....????????
    kirkostas
  • kapamaroukapamarou Member Posts: 1,152
    kapamarou wrote:
    think that filters applied in the onprereport trigger are reset to user's choice after that trigger.
    Add some dummy code in your OnPreDataItem Or OnAfterGetRecord and you'll see them missing! Set your filters on the OnPreDataItem trigger and test it...
  • kirkostaskirkostas Member Posts: 127
    Yes you are right.
    I put my code OnPreDataItem trigger and it works now.

    Also GETRANGEMAX gives me an error because the user write '010108..' and he never fill the MAX range.
    That's why I did it with COPYSTR.
    DateFilter := Date.GETFILTER("Period Start");
    IF COPYSTR(DateFilter, STRLEN(DateFilter), STRLEN(DateFilter)) = '.' THEN BEGIN
      EVALUATE(DateFilter2, COPYSTR(DateFilter, 1, STRLEN(DateFilter)-2));
      Date.SETRANGE("Period Start", DateFilter2, TODAY);
    END;
    

    Problem Solved.
    kirkostas
Sign In or Register to comment.