2 Fields, 1 Filter

AlkroAlkro Member Posts: 115
Hi!

I need to make a filter in txo fields in the same table, asking about the same value.

Example:

Field1 --> Owner
Field2 --> Buyer

I want to see all items that have a USER like owner OR buyer. (USER is a value in Owner field and Buyer field)

I'm looking this:

SETFILTER(Field, String [, Value] ,...) but, with this, i can make a filter only in a field, asking about two or more values.

How can i solve this?

Regards :)

Comments

  • WaldoWaldo Member Posts: 3,412
    You're not going to be able to do this with SETFILTER or SETRANGE.

    You can work with marking the records, or preferrably temp tables... :-k

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • krikikriki Member, Moderator Posts: 9,112
    Meaning: you need to loop the records for the first filter, mark or save them and then loop the records of the second filter.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AlkroAlkro Member Posts: 115
    Excuse me form my poor explain.

    I've a Form, when a user open the form, in the OnInit there is a filter that only can see only item that user is owner. There is another field, Buyer. Maybe user can be buyer but not owner. I want this item can be seen by this user.

    Now, this is the filter in OnInit:

    SETRANGE(Owner,USERID);


    Imagine: USERID = 'Peter';

    Table
    ITEM   |   OWNER   |   BUYER
    -----------------------------------
    001    | Peter   |   Anna
    002    | Anna    |   Peter
    003    | Anna   |   Anna
    004    | Peter   | Peter
    

    I want to see items 001, 002 and 004 in the form.

    Actually with the filter ( SETRANGE(Owner,USERID); ) only can see 001 and 004.
  • krikikriki Member, Moderator Posts: 9,112
    You can't do that with a normal filter.
    Or you loop the records and mark them (or use a temptable).
    Or you create a new field with both Owner and buy in them (e.g. ",Peter,Anna," with a , before AND after the names).
    Then you can filter on the new field:
    SETFILTER("New Field",'%1','*,Anna,*');
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,307
    So set 'PETER' filter on buyer, and also on owner. You'll find all records where both are 'PETER'.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    So set 'PETER' filter on buyer, and also on owner. You'll find all records where both are 'PETER'.

    I think he wants (Buyer = peter) or (Owner = peter) :wink: .

    Fundamentally though you need to rethink the design of the database. Work out all the scenarios before building the structure. If you had build this with a table where Owner/Buyer was an option string, then the primary key was
    Item No., Owner type, Code

    then a simpl flow field could do this with out any programming.
    David Singleton
  • WaldoWaldo Member Posts: 3,412
    Yes, but he just wants to indicate buyer and owner ... and in some cases they are the same. So I think his design is OK.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Waldo wrote:
    Yes, but he just wants to indicate buyer and owner ... and in some cases they are the same. So I think his design is OK.

    True we don't know the whole story, and this one filter requirement may be the only case not handled by the way its done. Its just that its quite normal when one such requirement comes along, and it the sort of work, the client soon asks for another mod, and then another. The cost of a table is generally far less that the cost of programming and working around.

    But re-reading everything, probably in this case you are right, and my solution is maybe a bit of an overkill.
    David Singleton
Sign In or Register to comment.