Copy Filterfields in a Report to another dataitem

ReSpongebob
Member Posts: 17
Hi,
I would like to copy the filterfields of a dataitem in a report to another dataitem in order to prevent users having to insert the same filter multiple times for each dataitem.
I've tried to use COPYFILTERS, but that's not possible, because I have different records. The error-message indicated that I had to copy the filters one by one.
My problem is that I don't know what filterfields will be filled by the user. I also don't know how many filterfields will be entered.
Is it possible to "loop" through all the filters, and copy them one by one? :-k
I would like to copy the filterfields of a dataitem in a report to another dataitem in order to prevent users having to insert the same filter multiple times for each dataitem.
I've tried to use COPYFILTERS, but that's not possible, because I have different records. The error-message indicated that I had to copy the filters one by one.
My problem is that I don't know what filterfields will be filled by the user. I also don't know how many filterfields will be entered.
Is it possible to "loop" through all the filters, and copy them one by one? :-k
0
Comments
-
No, I don't think there is such a thing. Just copy the filters field by field.
You might be able to do something with RecordRef and FieldRef, but then copying one by one is easier.0 -
Thanks for the quick reply.
But I'm not that experienced in programming C/AL.
How can I copy the filters one by one, if I don't know the fieldnames of the filters in advance? I also don't know how many filters there will be... :?0 -
IF Rec1.Field1.GETFILTER <> '' then
Rec2.Field1.SETFILTER(Rec1.Field1.GETFILTER);
:shock:
And then for all fields.....0 -
I was hoping for another answer...
unfortunately, I fear there is indeed no other option.
Thanks for the solution!0 -
Define variable RecRef type RecordRef
RecRef.GETTABLE("Table1");
RecRef.SETVIEW("Table2".GETVIEW);
"Table1".SETVIEW(RecRef.GETVIEW);
In the case where I used it table2 is almost a copy from table1.0 -
John wrote:Define variable RecRef type RecordRef
RecRef.GETTABLE("Table1");
RecRef.SETVIEW("Table2".GETVIEW);
"Table1".SETVIEW(RecRef.GETVIEW);
In the case where I used it table2 is almost a copy from table1.
Yes, this can work if the tables are (almost) identical, just keep in mind that the keys(sorting) are also in the view.0 -
John wrote:Define variable RecRef type RecordRef
RecRef.GETTABLE("Table1");
RecRef.SETVIEW("Table2".GETVIEW);
"Table1".SETVIEW(RecRef.GETVIEW);
In the case where I used it table2 is almost a copy from table1.
[/code]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
You can also loop through the fields with a fieldreference and take the filter on each field and apply it on the field in the other table.
I need to do this also. I can't figure out how to do it with a "fieldreference".
I would really appreciate some sample code.0 -
Karenh wrote:I would really appreciate some sample code.
Sorry it took so long, but I was very busy and hadn't time to see emails with replies.rerFrom.GETTABLE(recFrom); rerTo.GETTABLE(recTo); recField.RESET; recField.SETCURRENTKEY(TableNo,"No."); recField.SETRANGE(TableNo,DATABASE::Item); recField.SETRANGE(Enabled,TRUE); IF recField.FIND('-') THEN REPEAT firFrom := rerFrom.FIELD(recField."No."); firTo := rerTo.FIELD(recField."No."); firTo.SETFILTER(firFrom.GETFILTER); UNTIL recField.NEXT = 0;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
rerFrom.GETTABLE(recFrom); rerTo.GETTABLE(recTo); recField.RESET; recField.SETCURRENTKEY(TableNo,"No."); recField.SETRANGE(TableNo,DATABASE::Item); recField.SETRANGE(Enabled,TRUE); IF recField.FIND('-') THEN REPEAT firFrom := rerFrom.FIELD(recField."No."); firTo := rerTo.FIELD(recField."No."); firTo.SETFILTER(firFrom.GETFILTER); UNTIL recField.NEXT = 0;
I'm trying to use this piece of code since I have the same issue. However I don't understand what some of the variables should be set as. (ie what is recField,rerFrom...?)
Appreciate any help.
Dneal0 -
recFrom,recTo: some record variable
rerFrom,rerTo : recordreference
recField : record variable of table Field
firFrom,firTo : fieldreferenceRegards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Hi again,
I"m confused on what this code is doing exactly. I thought it was going to loop through all fields in one table and look for filters and put it in the second table.recField.SETRANGE(TableNo,DATABASE::Item); firFrom := rerFrom.FIELD(recField."No."); firTo := rerTo.FIELD(recField."No.");
But when I look at this I'm assuming I need to fill in the fields myself from each field to each field. Am I missing something? My apologies, I'm not that advanced with Nav programming. :?
Dneal0 -
I'll put some comments in it:
rerFrom.GETTABLE(recFrom); // put the from-record in a recordreference rerTo.GETTABLE(recTo); // put the to-record in a recordreference recField.RESET; recField.SETCURRENTKEY(TableNo,"No."); recField.SETRANGE(TableNo,DATABASE::Item); recField.SETRANGE(Enabled,TRUE); IF recField.FIND('-') THEN REPEAT // with the SETRANGE's, the IF - THEN - REPEAT - UNTIL loops through all enabled fields of table Item // Each time Navision gets in this place, in recField will be the next field of table Item. // (This you can check with MESSAGE('Fieldno.=%1',recField."No."); firFrom := rerFrom.FIELD(recField."No."); // point firFrom to field recField."No." in recordreference rerFrom firTo := rerTo.FIELD(recField."No."); // point firTo to field recField."No." in recordreference rerTo firTo.SETFILTER(firFrom.GETFILTER); // this takes the filter of firFrom and puts it in firTo // the first time Navision gets into the loop, this command would be the same as recFrom.SETFILTER("No.",recTo.GETFILTER("No."); UNTIL recField.NEXT = 0; // this last command must be added to convert recTo with all the filters in it to the record-variable. rerTo.SETTABLE(recTo);
I hope this makes it clearer.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
It's starting to make much more sense. May I ask, what do I set recField as? What do I declare it as in globals?
This is what I have done:rerFrom.GETTABLE("Sales Line"); rerTo.GETTABLE("Sales Invoice Line"); recField.RESET; recField.SETCURRENTKEY(TableNo,"No."); recField.SETRANGE(TableNo,DATABASE::"Sales Line"); //is this correct? recField.SETRANGE(Enabled,TRUE); IF recField.FIND('-') THEN REPEAT firFrom := rerFrom.FIELD(recField."No."); firTo := rerTo.FIELD(recField."No."); firTo.SETFILTER(firFrom.GETFILTER); UNTIL recField.NEXT = 0;
Thanks again for helping me.
Dneal0 -
Dneal wrote:It's starting to make much more sense. May I ask, what do I set recField as? What do I declare it as in globals?Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I'm still having issues getting this to work. When I first run it it tells me field 14010 doesn't exists in Sales Line. So I disabled it in the Sales Invoice Line just to get it to run. Of course I will need to put that back, do you know how I get past that error?
Also once I get it to run the filters are not being copied.
These are my dataitems.
DataItem Name
Customer <Customer>
Sales Header <Sales Header>
Sales Line <Sales Line>
Sales Invoice Header <Sales Invoice Header>
Sales Invoice Line <Sales Invoice Line>
I have put the code in the onaftergetrecord of the Sales Invoice Line and then tried it on the OnPreReport. But when I debug I'm not getting the results. When it's in the OnPreReport it just copies blanks. When it's on the OnAfterGetRecord it just sets the fields. Have I put it in the right place? Perhaps this is more advanced then I'm capable of doing.
Dneal0 -
Try this:
rerFrom.GETTABLE(recFrom); rerTo.GETTABLE(recTo); recField.RESET; recField.SETCURRENTKEY(TableNo,"No."); recField.SETRANGE(TableNo,DATABASE::Item); recField.SETRANGE(Enabled,TRUE); IF recField.FIND('-') THEN REPEAT IF rerFrom.FIELDEXIST(recField."No.") AND rerTo.FIELDEXIST(recField."No.") THEN BEGIN firFrom := rerFrom.FIELD(recField."No."); firTo := rerTo.FIELD(recField."No."); firTo.SETFILTER(firFrom.GETFILTER); END; UNTIL recField.NEXT = 0;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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