copy fieldfilters from 1 table to another

krikikriki Member, Moderator Posts: 9,112
edited 2007-12-04 in NAV Tips & Tricks
This topic I create as a remark to my post http://www.mibuso.com/forum/viewtopic.php?p=106339#106339.

I wanted to copy filters field by field from one table to another table.
So I thought to use recordreference and field reference to do it so to avoid 1 line of code per field to be copied.

These are the globals I need. All of them have 2 dimensions (1 for the source record and 1 for the destination record)
Name	DataType	Subtype	Length
recField	Record	Field	
rer	RecordRef		
fir	FieldRef

And this would be the code:
rer[1].GETTABLE("Sales Invoice Header");
rer[2].GETTABLE("Sales Cr.Memo Header");

// loop all fields of the record from which I want to copy the filters
recField[1].RESET;
recField[1].SETCURRENTKEY(TableNo,"No.");
recField[1].SETRANGE(TableNo,DATABASE::"Sales Invoice Header");
IF recField[1].FINDSET THEN
  REPEAT
    // get the field with the same fieldnumber in the second table
    IF recField[2].GET(DATABASE::"Sales Cr.Memo Header",recField[1]."No.") THEN
      // check if both fields are the same
      IF (recField[1].FieldName = recField[2].FieldName) AND
         (recField[1].Type = recField[2].Type) AND
         (recField[1].Len = recField[2].Len) AND
         (recField[1].Class = recField[2].Class) AND
         (recField[1].Enabled = recField[2].Enabled) THEN BEGIN
        // copy the field filter
        fir[1] := rer[1].FIELD(recField[1]."No.");
        fir[2] := rer[2].FIELD(recField[2]."No.");
        fir[2].SETFILTER(fir[1].GETFILTER);
      END;
  UNTIL recField[1].NEXT = 0;


rer[2].SETTABLE("Sales Cr.Memo Header");


All works fine UNTIL I executed the last command (SETTABLE): the filters are NOT copied!

Am I doing something wrong?
I checked the online help on GETTABLE and SETTABLE:
-SETTABLE has this : Use this function to make a recordref variable use the same table instance as a record variable. Any filters that are applied to the record are also applied to the recordref. If you change the filter that is applied to the record, you must call SETTABLE again to apply the new filter to the recordref.
-GETTABLE has this: Use this function to make a recordref variable use the same table instance as a record variable.

So this means, it does NOT copy the filters from the recordreference to the table.
Even worse : IT REMOVES ALL THE FILTERS FROM RECORDREFERENCE!
I have tested this with NAV 5.0 without hotfixes.


This means you have to copy all the fields 1 by 1 using the tables and not recordreferences.


I hope MS fixes this bug. I consider this a bug because the GETTABLE and SETTABLE should be each others opposite and they are not.

I know it is a little strange putting this post in the Navision Tips & Tricks-forum, after all it is something that DOESN'T work. But also this can help others. Someone might need it, search the forum. See exactly the code he needs and know immediately that it doesn't work. :cry::cry::cry::cry::cry::cry:
At least he didn't invest time to program it and find out why it doesn't work (I put more time to search why it didn't work than to program it!).
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Comments

  • BeliasBelias Member Posts: 2,998
    edited 2007-12-03
    Did you try to use settable in stead of gettable?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • krikikriki Member, Moderator Posts: 9,112
    al posto di=in stead of

    settable serves to put a recordreference into a record and
    gettable serves to pu a record into a recordreference

    So the gettable at the begin I use to put both records into the recordrefrences.

    At the end I have to return the destination-recordreference into the record and this does not work.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • jreynoldsjreynolds Member Posts: 175
    I reported this problem with SETTABLE to Microsoft 2 1/2 years ago and they basically said they weren't going to fix it. The final response I had was that they would change the manual.
  • BeliasBelias Member Posts: 2,998
    thanks 4 translation...what a "lapsus"!!
    there is a part in the help that makes me suspicious...

    "If you change the filter that is applied to the record, you must call SETTABLE !!again!! to apply the new filter to the recordref"

    the "again" maybe means that you have to use SETTABLE before and after the filters, but the GETTABLE would lose sense...
    The help also says (either in get and set)

    "Use this function to make a recordref variable use the same table instance as a record variable."

    so i have made my considerations (that are probably wrong...sorry but i couldn't try)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • ajhvdbajhvdb Member Posts: 672
    A workaround?:

    Before the transfer do a getview. After the transfer do a setview.
  • kinekine Member Posts: 12,562
    Look for the SETVIEW and GETVIEW to transfer filters between recordref and record.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.