Copy contents from one table to other table-Transferfields?

ntnt Member Posts: 160
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?

Thanks.

Comments

  • KowaKowa Member Posts: 925
    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).

    Example :
    Item2 := Item;
    Item2.COPY(Item);
    Kai Kowalewski
  • ntnt Member Posts: 160
    thanks, i'm using transferfields, but the id of the fields in the 2 tables ate not the same...what i have to do?
  • kinekine Member Posts: 12,562
    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.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.