Union filter

Cem_KaraerCem_Karaer Member Posts: 281
Hi all,
I have a table which contains two boolean fields say A and B.
To filter out only A clicked rows I can use:
Table.SETRANGE(A,true)
Table.SETRANGE(B,false)
To filter out only B clicked rows:
Table.SETRANGE(A,false)
Table.SETRANGE(B,true)
To filter out only A AND B clicked rows:
Table.SETRANGE(A,true)
Table.SETRANGE(B,true)
Here's the question: What about A OR B clicked rows?
(Using option field instead of two boolean fields is not applicable)
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005

Comments

  • garakgarak Member Posts: 3,263
    edited 2008-07-10
    Table.SETRANGE(A,true);
    if Table.findset(false,false) then begin
      repeat 
        Table.mark(true);
      until Table.next = 0; 
    end;
    
    Table.SETRANGE(A);
    Table.SETRANGE(B,true);
    if Table.findset(false,false) then begin
      repeat 
        Table.mark(true);
      until Table.next = 0; 
    end;
    Table.SETRANGE(B);
    Table.markedonly(true);
    

    or
    TempTab.deleteall;
    Table.SETRANGE(A,true);
    if Table.findset(false,false) then begin
      repeat 
        TempTab.Identifer := Table.Identifer;
        TempTab.insert;
      until Table.next = 0; 
    end;
    
    Table.SETRANGE(A);
    Table.SETRANGE(B,true);
    if Table.findset(false,false) then begin
      repeat 
        if not TempTab.get(Table.Identifer) then begin
          TempTab.Identifer := Table.Identifer;
          TempTab.insert;
        end;
      until Table.next = 0; 
    end;
    
    or without the filter (Field A / B) but with a if statement in the loop
    Now you can loop throug you temptab.
    other way: new field wich stores the value := A OR B
    

    Hope it's understandable.

    Regards
    Do you make it right, it works too!
  • awarnawarn Member Posts: 261
    I think you need a new (third) field, which would not show on the form.

    OnValidate of both of your current fields, you call a function:

    NewFunction

    FieldC := fieldA OR fieldB;


    then you filter on field C, which will contain TRUE if A or B is ever TRUE.
  • Cem_KaraerCem_Karaer Member Posts: 281
    Can I use FILTERGROUP function for this purpose?
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • awarnawarn Member Posts: 261
    It really doesn't apply here (in the sense that you cannot use it to do an OR) - unless you are trying to hide the filter that is on fieldC. Then you can use it.

    Filtergroup just hides filters from the user (and other parts of the code).

    Generally speaking, you can't have a SELECT statement with an OR in Navision. You have to filter on a field, you can't filter on fieldA = X OR fieldB = Y.

    There are ways with temporary tables, looping through the data once for each condition, but this could take a long time depending on how much data you have, and the solution here is a bit simpler.
Sign In or Register to comment.