Lookup filter in report

colingbradleycolingbradley Member Posts: 162
Report.
NAV 2009 Classic.

I need to be able to filter the customer records when the user looks up the No. field from the dataitem Customer.

I have tried:

Report - OnInitReport()
Customer.FILTERGROUP(2);
Customer.SETRANGE("Rebate Customer Type", 2); //Customer."Rebate Customer Type"::Rebate);
Customer.FILTERGROUP(0);

The above is not working although suggested by someone on another forum.
The user should not be restricted elsewhere, just for this report.

The report has a filter anyway so there is nothing going to happen if the user selects the wrong record but I am hoping there is a way of pre-filtering the list?

](*,)
Experience is what you get when you hoped to get money

Comments

  • colingbradleycolingbradley Member Posts: 162
    OK, not perfect but I have added the No. field on the request Form:

    <Control1000000000> - OnLookup(VAR Text : Text[1024];) : Boolean
    Cust.FILTERGROUP(2);
    Cust.SETRANGE("Rebate Customer Type", 2); //Customer."Rebate Customer Type"::Rebate);
    Cust.FILTERGROUP(0);
    IF FORM.RUNMODAL(0,Cust) = ACTION::LookupOK THEN
    Customer."No." := Cust."No.";

    That at least filters the records but is not what I was hoping for as I need to be able to select a range.

    :-k ........
    Experience is what you get when you hoped to get money
  • matttraxmatttrax Member Posts: 2,309
    Saw your post on DynamicsUser. This one is a bit more clear. Try adding this nice little function to the list form. I honestly can't remember if it was a base function on some of the forms in NAV 2009 SP1 or if I wrote it :lol: This one is from the Item List form, so you'll have to change it a little.
    CurrForm.SETSELECTIONFILTER(Item);
    ItemCount := Item.COUNT;
    IF ItemCount > 0 THEN BEGIN
      Item.FIND('-');
      WHILE ItemCount > 0 DO BEGIN
        ItemCount := ItemCount - 1;
        Item.MARKEDONLY(FALSE);
        FirstItem := Item."No.";
        LastItem := FirstItem;
        More := (ItemCount > 0);
        WHILE More DO
          IF Item.NEXT = 0 THEN
            More := FALSE
          ELSE
            IF NOT Item.MARK THEN
              More := FALSE
            ELSE BEGIN
              LastItem := Item."No.";
              ItemCount := ItemCount - 1;
              IF ItemCount = 0 THEN
                More := FALSE;
            END;
        IF SelectionFilter <> '' THEN
          SelectionFilter := SelectionFilter + '|';
        IF FirstItem = LastItem THEN
          SelectionFilter := SelectionFilter + FirstItem
        ELSE
          SelectionFilter := SelectionFilter + FirstItem + '..' + LastItem;
        IF ItemCount > 0 THEN BEGIN
          Item.MARKEDONLY(TRUE);
          Item.NEXT;
        END;
      END;
    END;
    EXIT(SelectionFilter);
    

    You'll want to declare your form as a variable and use that method to set the filter (it returns a text variable).

    SETFILTER("No.", CustomerListForm.GetSelectionFilter);
  • rhpntrhpnt Member Posts: 688
    Never mind...
  • vaprogvaprog Member Posts: 1,116
    As far as I know it is not possible to set any filters programmatically from within the report such that it is effective at the time the request form is shown.
    There are two approaches you can take:
    1. Use the DataItemTableView property
    2. Use SETTABLEVIEW before you run the report. You may use the default filtergroup so the filter is visible in the request form, or you can use a different filtergroup on the rec you use as a parameter for SETTABLEVIEW to hide the filter from the user
    In any of these cases the filter is effective on lookup and during the report.
Sign In or Register to comment.