Options

OR case for record filtering

kenlkenl Member Posts: 182
Hello,

How can we set "OR" case record filtering ?

Eg. on table 18 Customer, I would like to filter records that are

1) Country Code = 'US'
OR
2) Balance (LCY) > 0

If I write something like this:

Customer.SetFilter("Country Code", 'US');
Customer.SetFilter("Balance (LCY)", '>0');

This would give me the "AND" case.

Any idea?
:-k

Comments

  • Options
    toennetoenne Member Posts: 38
    there is no direct way to OR filters, i think, but try to patch the wanted records together by using the mark mechanism:
    Customer.SetFilter("Country Code", 'US'); 
    if Customer.find('-') then
      repeat
        Customer.Mark(true);
      until next = 0;
    Customer.SetRange("Country Code"); 
    
    Customer.SetFilter("Balance (LCY)", '>0'); 
    if Customer.find('-') then
      repeat
        Customer.Mark(true);
      until next = 0;
    Customer.SetRange("Balance (LCY)"); 
    
    Customer.MarkedOnly(true);
    
    

    maybe it's not very performant, but on small to medium tables it works :?
  • Options
    kenlkenl Member Posts: 182
    Hello Toenne ,

    Thanks for your idea.

    Ken
    [/code]
  • Options
    eromeineromein Member Posts: 589
    Or....

    You could create a Temporary record and insert all records that apply to your filtering.
    Cust.FIND('-');
    REPEAT
      IF (foo = bar) OR 
         (bar = foo)
      THEN BEGIN
        TEMPCust := Cust;
        TEMPCust.INSERT;
      END;
    UNTIL Cust.NEXT = 0;
    
    FORM.RUNMODAL(0, TEMPCust);
    
    * Code has not been tested.

    BTW, Marking records perform perfectly as long as you select the primairy key. If you need to set another key it's better to you code above... I think... ;)
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • Options
    Timo_LässerTimo_Lässer Member Posts: 481
    eromein wrote:
    [...]
    BTW, Marking records perform perfectly as long as you select the primairy key. If you need to set another key it's better to you code above... I think... ;)
    To set the record marked, you don't need the primary key.
    You should have the best key dependend to your filter.

    Before you set Cust.MARKEDONLY := TRUE it is recommended to change the key to the primary key because with that key you get the best performance for viewing the records.
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
Sign In or Register to comment.