Options

Setting filt. on multiple fields and sowing the joint result

emkproemkpro Member Posts: 47
I try to make a filter which shows the result of

rec.Setfilter(Field1,Value1)
rec.Setfilter(Field2,Value2)
and show the sum of all filtered records
//EMK\\

Comments

  • Options
    alanperualanperu Member Posts: 23
    Hi,

    What result do you want?

    If you just want to know the number of records left after you have applied your filters you use rec.COUNT. If you want to sum a field from the remaining records you will need to loop through them add keep a running total.

    Example:

    rec.Setfilter(Field1,Value1)
    rec.Setfilter(Field2,Value2)
    total = 0;
    REPEAT
    total += rec.FieldX;
    UNTIL rec.NEXT = 0;

    Does this help?
  • Options
    emkproemkpro Member Posts: 47
    No, what I want is a list of records which are "created by" "x" OR "modified by" "y". Created by and Modified by are two different fields of the same record.
    //EMK\\
  • Options
    kinekine Member Posts: 12,562
    You cannot use OR between fields... there is always AND between filters on fields... you must do it in two steps...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    randrewsrandrews Member Posts: 135
    May be something like that? It shows list of rec where Field1=Value1 OR Field2=Value2.
    rec.Setfilter(Field1,Value1) 
    IF rec.FIND('-') THEN
    REPEAT
      rec.MARK(TRUE);
    UNTIL rec.NEXT = 0;
    rec.SETRANGE(Field1);
    rec.Setfilter(Field2,Value2) 
    IF rec.FIND('-') THEN
    REPEAT
      rec.MARK(TRUE);
    UNTIL rec.NEXT = 0;
    rec.SETRANGE(Field2);
    rec.MARKEDONLY(TRUE);
    
  • Options
    emkproemkpro Member Posts: 47
    That seems ok.

    Something bothers me though: why rec.Setfilter(Field1,Value1) and then rec.SETRANGE(Field1); is it necessary ?
    :oops: i realized now it releases the first filter thanks..

    randrews wrote:
    May be something like that? It shows list of rec where Field1=Value1 OR Field2=Value2.
    rec.Setfilter(Field1,Value1) 
    IF rec.FIND('-') THEN
    REPEAT
      rec.MARK(TRUE);
    UNTIL rec.NEXT = 0;
    rec.SETRANGE(Field1);
    rec.Setfilter(Field2,Value2) 
    IF rec.FIND('-') THEN
    REPEAT
      rec.MARK(TRUE);
    UNTIL rec.NEXT = 0;
    rec.SETRANGE(Field2);
    rec.MARKEDONLY(TRUE);
    
    //EMK\\
Sign In or Register to comment.