Newbie: Cannot make filter relect Form View

allenmanallenman Member Posts: 37
I have a very basic question which shows my skill level in C/AL programming but please bear with me.

I have a simple tabular form1 based on table1. When I only required a single filter, I simply set the Form1 property of
SourceTableview to Where(Completed=Filter(0)).
This worked well and as records were marked completed they were removed from the form1 view.

Now, because I needed control over my filters I have been trying to set this filter (and others) in code. I thought it would be something as simple as
V_Count.SETCURRENTKEY(Completed)
V_Count.SETFILTER(Completed, '0')
Now, I also use the record variable V_Count in a SUM to count the number of non-complete records and this number changes correctly with the above code, so I believe my filter is working correctly.
But Form1 still shows all records, is my filter actually NOT working as I intended or do I need to add some update code?

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What is the V_Count variable?

    If you want to set filters in a form you need to put them on the Rec variable.

    Otherwise you will set them on the variable only.

    Maybe you can try:

    SETFILTER(Completed, '0')
  • ngebhardngebhard Member Posts: 127
    I suggest that what you are trying to do is a SETRANGE.
    V_Count.SETCURRENTKEY(Completed) 
    V_Count.SETRANGE(Completed, '0')
    
    This should actually work if completed is supposed to be zero.
    If you wanna use SETFILTER see the Navision help:
    SETFILTER (Record)
    Use this function to assign a filter to a field you specify.
    
    Record.SETFILTER(Field, String, [Value],...)
    Record
    
    Data type: record
    
    The record that contains the field you want to filter.
    
    Field
    
    Data type: field
    
    The field you want to filter.
    
    String
    
    Data type: text or code
    
    The filter expression. A valid expression consists of alphanumeric characters and one or more of the following operators: <, >, *, &, |, and =. You can use replacement fields (%1, %2, and so on) to insert values at run-time.
    
    Value
    
    Data type: any
    
    Replacement values to insert in replacement fields in the filter expression. The data type of Value must match the type of Field.
    
    
    V_Count.SETCURRENTKEY(Completed) 
    V_Count.SETFILTER(Completed,'%1','0') 
    
    This code should work as well.

    Greetz
    Nicole
    ProTAKT Projekte & Business Software AG
    Microsoft Dynamics NAV Partner
    Bad Nauheim, Germany
    http://www.protakt.de
    http://twitter.com/protakt
  • ngebhardngebhard Member Posts: 127
    One more thing:
    don't forget Marks posting. I regarded "V_Count" as a table and "Completed" as a field of the table.
    ProTAKT Projekte & Business Software AG
    Microsoft Dynamics NAV Partner
    Bad Nauheim, Germany
    http://www.protakt.de
    http://twitter.com/protakt
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Another thing 8)

    When using SETRANGE remove the '' if you filter on an INTEGER

    SETCURRENTKEY(Completed) 
    SETRANGE(Completed, 0)
    
  • allenmanallenman Member Posts: 37
    Thanks Mark Brummel that has worked perfectly.
    I could not get out of the mindset of attempting to use CurrForm.SETFILTER(Completed, '0')

    I'm a little embarassed that I did not try this and thankyou for taking the time to help.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Don't be embarassed :shock:

    Good luck learning Navision 8)
Sign In or Register to comment.