copy fieldfilters from 1 table to another

kriki
Member, Moderator Posts: 9,121
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)
And this would be the code:
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.





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!).
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.






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!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
0
Comments
-
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!0 -
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.0
-
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)0 -
A workaround?:
Before the transfer do a getview. After the transfer do a setview.0 -
Look for the SETVIEW and GETVIEW to transfer filters between recordref and record.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions