Options

Form Filter Trigger

raieesraiees Member Posts: 33
Hi,
I have a form , it has an option field Status Current and History.
I have put a option control 'Show Options' in the form to filter the status field
If status 'Current Only' is selected, the form displays all current records and if status 'History only' is selected the forms shows all History records.

if user chooses Form filters (Field Filter Table Filter and Show All), the form shows accordingly and overruled the option control filter and option control shows wrong status.

My question is how we can track form filters so I can change option control accordingly.

Thanks in Advance

Comments

  • Options
    SavatageSavatage Member Posts: 7,142
    Let me see if I can get you to clarify a bit.

    So (for example) You're looking at a customers ledger entries.
    You want a textbox at the bottom of the page called status.
    The status button has 3 options
    1.View All
    2.View Current
    3.Vew History

    when selecting one of these options you want the form to filter.
    In this case I will use the field "OPEN" to determine what is current and what is history

    am i in the ballpark?
  • Options
    kinekine Member Posts: 12,562
    If I understand correctly, problem is, that when user use the standard way to set filter, the added fields for filtering are not "in sync" the reality.

    There is no such trigger for setting filters. You need to get the actual filters and set the values to correct one e.g. in OnAfterGetRecord because each time you change filter, lines are re-readed. But you should optimize it to not seth the values when not needed...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    raieesraiees Member Posts: 33
    Hi Savatage,
    Yes you are right.
    I have done up to your point.
    But as Kine said, my problem comes when user uses standard filter.
    When user says View Current so customer ledger entries form shows all open entires but after that user uses standard filter Show All (Shift+Ctrl+F7) so now the form shows all entries but my option button shows Current only. so it is not 'sync'

    Kine,
    As you suggested If I get the filter in OnAfterGetRecord, every time records are updated, will execute my code. I want to execute it when Standard filter is set.
    Any suggestion?
  • Options
    garakgarak Member Posts: 3,263
    Here the source that kine means.
    if getfilters(YourOptionFieldinTable) <> '' then begin
      //here u set the values for the YourOptionTextboxVariable
    end else 
      YourOptionTextboxVariable := '';
    

    But why do you which a TextBoxControl for filter? Only for more "easely filter for the user or why. Why the users not use Ctrl+F7.With Ctrl+F7 they are more flexible.

    Like a filter with F7 on YourOptionFieldinTable:
    <>Open&<>Closed&<>Checked

    Would you add all possible filtercriterias to your YourOptionTextboxVariable? I Think not, so why not using the default Filterfunction (Ctrl+F7 or only F7 if the field is enabled)?


    Regards
    Do you make it right, it works too!
  • Options
    raieesraiees Member Posts: 33
    Hi Garek,

    Thanks for your input.

    They need only one filter 'Status' on the form, users say the filter is visible on the form so easy to know it. and they can use Field or Table filter for other fields
    Its Users wish and we need to fulfill :P
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Just create a function to update the form based on the filter and call this on after get record.

    MyFunction()
    Case GETFILTER(Status) OF
    'Current':
    IF MyStatus <> MyStatus::Current THEN
    MyStatus := MyStatus::Current;
    'History':
    IF MyStatus <> MyStatus::History THEN
    MyStatus := MyStatus::History;
    Else
    BEGIN
    SETRANGE(Status);
    MyStatus := MyStatus::All;
    END;
    END;

    This will allow for the filter to be set from the fieldfilters, and your existing code from the form, if you want your form variable to set the filter

    MyFunction()
    Case GETFILTER(Status) OF
    'Current':
    IF MyStatus <> MyStatus::Current THEN
    SETRANGE(Status,Status::History);
    'History':
    IF MyStatus <> MyStatus::History THEN
    SETRANGE(Status,Status::Current);
    Else //Set to Default
    SETRANGE(Status,Status::Current);
    END;

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    DaveTDaveT Member Posts: 1,039
    Hi

    Another suggestion is to use FILTERGROUP so the the end user cannot remove your filter and then change it by the option selection.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • Options
    raieesraiees Member Posts: 33
    Thanks David,
    I had already coded as you suggested here but I liked Dave idea to use FILTERGROUP.
    Now user can only filter from option button only.

    Thanks for all
  • Options
    SavatageSavatage Member Posts: 7,142
    I've added a Global Variable Called: ViewStatus type option
    The Options of this field Are: "View All", "View Current","View History"
    I added a textbox to the bottom of the form: SourceExp=ViewStatus
    Make sure your glues are bottom, left

    Add this code to the Textbox c/al code
    OnAfterValidate()
    CASE ViewStatus OF 
    ViewStatus::"View All":
     BEGIN
      RESET;
      SETCURRENTKEY("Entry No.");
      SETFILTER("Customer No.","Customer No.");
     END; 
    ViewStatus::"View Current":
     BEGIN
      RESET;
      SETCURRENTKEY("Entry No.");
      SETFILTER("Customer No.","Customer No.");
      SETFILTER(Open,'Yes');
     END; 
    ViewStatus::"View History":
     BEGIN
       RESET;
       SETCURRENTKEY("Entry No.");
       SETFILTER("Customer No.","Customer No.");
       SETFILTER(Open,'No');
     END; 
    END;
    CurrForm.UPDATE;
    
Sign In or Register to comment.