Options

Copyfilter from multiple filtergroups

gazpachogazpacho Member Posts: 48
Hi there,

I have a form that displays sales lines. A filter is set on a couple of fields on opening the form. These filters may not be removed, so they are set in filtergroup 0. The user is allowed to further refine the view by setting more filters (in filtergroup 2).

In a function in the sales line table, I want to define a new record variable (salesline2) that has the same filters as the table above.

the code "salesline2.copyfilters(rec)" would seem a logical solution. But this does not work because I have 2 filtergroups on the original table. How can I copy the filters of both filtergroup 0 and 2 to the new record variable?

Best regards

Gazza

Comments

  • Options
    ara3nara3n Member Posts: 9,255
    you can loop through filtergroups
    for I:= 0 to 255 do begin
      FILTERGROUP(I);  
      salesline2.FILTERGROUP(I);
      salesline2.copyfilters(rec)
    end;
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    krikikriki Member, Moderator Posts: 9,089
    PS the users should work in filtergroup 0.
    Filtergroups 1 to 7 (I think) is reserved by Microsoft.
    So put your filters that may not be removed by the user starting from filtergroup 10.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    gazpachogazpacho Member Posts: 48
    Looping through the filtergroups and perform a copyfilter works fine, but only if the different filtergroups does not contain the same fields.

    Example:
    In the OnOpenForm trigger, the following filters are set by Navision:
    filtergroup(2);
    table.SETFILTER(Manager,'%1','JOHN|PETER');
    table.SETRANGE(IsOpen,TRUE);
    table.SETRANGE(IsPositive,TRUE);
    filtergroup(0);

    Then, once the user is on the form he narrows this view down to
    Manager = PETER by setting a filter.

    Thus, the combined filter of groups 0 and 2 is the following:
    table.SETFILTER(Manager,'%1','PETER');
    table.SETRANGE(IsOpen,TRUE);
    table.SETRANGE(IsPositive,TRUE);

    When I cycle through the filtergroups and perform a copyfilters() on each group, the final result is that only the filters from the last group are copied. It seems the filters get reset once a copyfilters() is performed

    Is there another way?

    Best regards

    Gazz
  • Options
    jreynoldsjreynolds Member Posts: 175
    salesline2.COPY(rec)
    

    This copies all filter groups. Beware that it copies some other things as well (e.g. marks, current key).
  • Options
    DmytroYDmytroY Member Posts: 1
    All filters are copied and remain in their assigned group numbers. For example: Rec.CopyFilters(FromRec); disregards the current filter group on both Rec and FromRec, and copies all filters in FromRec (regardless of group number) into the same filter group assignments on Rec.

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-copyfilters-method
Sign In or Register to comment.