Record Variable query

NRNR Member Posts: 78
I have two recordsets filtered on different fields of an identical table.
Is it possible to have it copied to a third recordset with record source of that same table.

For eg. I have 2 Record Variable of Item table
ItemRec1 - Which is filtered on No. 1000
ItemRec2 - which is filtered on No. 1100

Now, what is the appropriate way to copy it to a third Record Variable ItemRec3


  • Options
    prasslprassl Member Posts: 24
    Hi NR,

    as I understand your problem, you need a record variable that includes both,
    No. 1000 and No. 1100 is that correct ? :-k :-k

    In order to achieve that, you do not need 3 instances of the same record variable, in fact, 1 record variable with an appropriate filter will do the same:

    So, your global variable is:

    ItemRec1 - Type is Record, Subtype is the Table you need

    If you want that record variable to represent all Records in it where No. = 1000 and No. = 1100 you can do so by using:

    ItemRec1.SETFILTER("No.", '%1 | %2', '1000', '1100');

    "No." = the table field the filter is applied to
    '%1 | %2' = the filter string, %1 and %2 are replaced by the parameters following, | is the logical OR
    '1000' = replaces %1 on executing
    '1100' = replaces %2 on executing

    have a look at the C/SIDE reference in NAV, it shows the appropriate use of SETFILTER and its possibilities with |, &, .. etc.

    Also, remember, when using the record variable later to retrieve its records 1 by 1 using FIND instead of GET, as FIND respects the setting of filters, which GET doesn't.

    ... I am not a programmer, I just write code.
  • Options
    NRNR Member Posts: 78
    thankx manu...... for the solution
  • Options
    Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    However, there might be some limitations on how long a filter can be (I am not sure, but I guess)

    Couldn't you just describe the business problem instead?
  • Options
    girish.joshigirish.joshi Member Posts: 407
    In this case, the problem is simple, because the field you are filtering on is the primary key of the table.

    But if the records were filtering on different fields that weren't primary keys, and you wanted to "merge" the results, you would have to do things differenlty.

    for instance you want all records where the gen. prod posting group = rawmat OR the inventory posting group = domestic

    in this case, you have to declare to records variables, and set the filter on each. Then declare a third temp variable. You loop through both sets, and try to insert all of them into temp. For instance
    TempItem.deleteall ;
    Item1.setrange("gen. prod posting group", rawmat) ;
    if Item1.find('-') then
        TempItem.Transferfields( Item1 ) ; 
        TempItem.Insert ;
      until Item.next  = 0
    Item1.reset ;
    Item1.setrange("inventory posting group", domestic) ;
    if Item1. find('-') then 
        TempItem.transferfields (Item1) ;
        if TempItem.Insert then ; 
      until Item1.next = 0 

    This always you set "OR" filters between fields -- instead of cumulative filters the way standard navision does.
  • Options
    girish.joshigirish.joshi Member Posts: 407
    There is a limit on how long a filter can be. If I remember correctly its 250 chars.... somewhere near there anyway :-k
Sign In or Register to comment.