Hi, someone can help me with an example with transferfields function?
I need to copy the contents(fields and values) from a table to another table(or from one record to another record).
Wich is the best way to do that?
If you have different tables, use TRANSFERFIELDS ( Copies values based on the field ID ).
Example : SalesShptHeader.TRANSFERFIELDS(SalesHeader);
If it used as : SalesShptHeader.TRANSFERFIELDS(SalesHeader,TRUE); ( or without this parameter)
then the primary key fields of the SalesShptHeader will be initiated
otherwise use SalesShptHeader.TRANSFERFIELDS(SalesHeader,FALSE);
If it is a different record variable for the same table , use an assignment
":=" ( if you want the values without the filters)
or the COPY Function ( if you want to copy the filters too).
Try to use fieldref and recref to cycle through all fields and assign fields with same name... BUT I CANNOT SUGGEST IT, because after that someone rename field and you are in big trouble... :-)
Best way is to have same field nos. If not, hardcode the assignment. Some other automatic assignment can be problematic.
Comments
Example :
SalesShptHeader.TRANSFERFIELDS(SalesHeader);
If it used as :
SalesShptHeader.TRANSFERFIELDS(SalesHeader,TRUE); ( or without this parameter)
then the primary key fields of the SalesShptHeader will be initiated
otherwise use
SalesShptHeader.TRANSFERFIELDS(SalesHeader,FALSE);
If it is a different record variable for the same table , use an assignment
":=" ( if you want the values without the filters)
or the COPY Function ( if you want to copy the filters too).
Example :
Item2 := Item;
Item2.COPY(Item);
Best way is to have same field nos. If not, hardcode the assignment. Some other automatic assignment can be problematic.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.