Using an OR filter on a Page with FILTERGROUP(-1) - any issues?

pdjpdj Member Posts: 643
Say you need to show a list customers either living in the US or having a phone no. starting with +1
Inspired by Luc's article at https://dynamicsuser.net/nav/b/vanvugt/posts/filtergroup-1 I decided to try using the -1 filtergroup. I was very easy setting the filters, and marking the records and show them in the list.

However; that did't quite solve my problem. If the user opens the Customer Card and changes the country code or phone no. it needs to disappear from the list. As I'm using marks I need some way to trigger a reload of the marked records, but there doesn't seem to be any trigger to use.

I then came to think of the old way of showing a temporary record in a form, before the SourceTableTemporary property was introduced. You might recall that method was used in the Navigate form, by adding code in the OnFindRecord() and OnNextRecord() triggers.

I then simply copied this old style code into my NAV2016, and now it works like a charm :blush:

My only concern is that I might have overlooked something, and that this approach doesn't work in all scenarios. The performance isn't as good as using marks, but in my case the performance is not an issue. Do you see any other issues with this solution?
Regards
Peter

Answers

  • pdjpdj Member Posts: 643
    edited 2016-11-30
    The only issue I have encountered, is that the filters set by the user was ignored. I fixed that by replacing the simple record assignment with a rec.COPY, but then I also need to assign my own filters all the time. (And then I could delete my code in OnOpenPage)

    My code ended up like this:
    OnFindRecord(Which : Text) : Boolean
    // >> XXX
    //g_GlobalRec := Rec;
    g_GlobalRec.COPY(Rec);
    f_SetMyFilters;
    IF NOT g_GlobalRec.FIND(Which) THEN
      EXIT(FALSE);
    Rec := g_GlobalRec;
    EXIT(TRUE);
    // << XXX
    
    OnNextRecord(Steps : Integer) : Integer
    // >> XXX
    //g_GlobalRec := Rec;
    g_GlobalRec.COPY(Rec);
    f_SetMyFilters;
    l_CurrentSteps := g_GlobalRec.NEXT(Steps);
    IF l_CurrentSteps <> 0 THEN
      Rec := g_GlobalRec;
    EXIT(l_CurrentSteps);
    // << XXX
    
    LOCAL f_SetMyFilters()
    // >> XXX
    WITH g_GlobalRec DO BEGIN
      FILTERGROUP(-1);
      SETRANGE("Country Code",'US');
      SETFILTER("Phone No.",'+1*');
      FILTERGROUP(0);
    END; 
    // << XXX
    

    PS: The filters are only for the example. The real scenario is a lot more complex :smile:
    Regards
    Peter
  • MaxxMaxx Member Posts: 10
    Nice solution!
    Thank you. You saved a lot of my time.

    Works at Dynamics NAV 2017.
    Few remarks:
    1. Page should have property SourceTableTemporary = Yes
    2. Insert / Delete updates list correctly.
    3. Consider about support in newer versions (BC, 2019)
Sign In or Register to comment.