Setting a filter in a report programmatically

rnshhrnshh Member Posts: 22
Is it possible to set a filter programmatically for a DataItem in a report? I've used <dataitem>.setrange, <dataitem>.setfilter, passing a string with the desired filter. Each time I run the report, it appears to not have any filters at all!

Thx in advance.
Tim Lecander
ArcherPoint

Comments

  • krikikriki Member, Moderator Posts: 9,110
    You need to define the filter in the OnPreDataItem of the dataitem. Probably also the OnPreReport works but I only used it to save the filters and not to change them.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    You cannot set the "visible" filters on the request form in other way than setting the filter on the record passed to the report when running it. But you can set the filters in OnPreDataitem as Kriki wrote...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ReinhardReinhard Member Posts: 249
    it seems like there are three incomplete ways to do this:

    1. OnPreDataItem
    method: write code in this trigger to filter the recordset
    advantage: quick and easy
    disadvantage: no way to set the filter dynamically

    2. custom function
    method: create a function in your report to set the filter. Or at least the parameters to be used in method 1.
    advantage: can set filters dynamically
    disadvantage: you have to instantiate the report before you can set the filters

    3. pass in filtered record
    method: first set filters on recordset then call
    REPORT.RUN(ReportID, FALSE, FALSE, recordSet)
    
    advantage: dynamic filtering wihtout having to instantiate the report first
    disadvantage: you can only filter one table

    correct me if I am wrong.
  • rnshhrnshh Member Posts: 22
    kriki wrote:
    You need to define the filter in the OnPreDataItem of the dataitem. Probably also the OnPreReport works but I only used it to save the filters and not to change them.

    Thanks to all of you for the quick reply. I had been setting the filter only at OnPreReport, I didn't think :oops: of placing it in OnPreDataItem.

    Thanks so much, all!
    Tim Lecander
    ArcherPoint
Sign In or Register to comment.