Options

how to copy the records from one table to another table

amtamt Member Posts: 3
hai all
i am new to navision programming
i have a problem in coping the records from a perticulat field of a table to another table
for example
item1 is the table which i have created
i want to copy all the item nos from item table to item1 table's itemno field which is not a primary key.
All the records should be copied at a time.
is it possible?
i have tried in so many ways but not able to get . ](*,)
i think it is understandable,
please help me in this senario
thanks in advance

Comments

  • Options
    Revolution1210Revolution1210 Member Posts: 161
    This is the general structure of what you need, assuming that the records don't already exist in your new target table:
    Item.RESET;
    IF Item.FINDFIRST THEN REPEAT
      Item2.INIT;
      ..
      Item2."Item No." := Item."No.";
      ..
      Item2.INSERT;
    UNTIL Item.NEXT = 0;
    

    Item would be a Record type variable pointing to the Item table, Item2 would be a Record type variable pointing to your new table.

    Also, you say that the Item No. field in your target table is not the primary key? If so, you would need to fill in your primary key fields as well.
    Ian

    www.NextEqualZero.com
    A technical eye on Dynamics NAV
  • Options
    jlandeenjlandeen Member Posts: 524
    As an alternative solution to the one proposed above you may want to try using the TRANSFERFIELDS Function. The one requirement of using this function is that field types, lengths and ID's match (as it uses the Field No property to copy fields).
    IF Item.FINDSET THEN BEGIN
      REPEAT
        CLEAR(NewRecord);
        NewRecord.TRANSFERFIELDS(Item);
        NewRecord.INSERT;
      UNTIL Item.NEXT = 0;
    END;
    

    This function can be used to copy fields between record types that are not the same (e.g. use TransferFields to copy data from a Sales Line record to a Sales Inv. Line record).

    Check out the online documentation of TRANSFERFIELDS(Record) in Navision help.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • Options
    amtamt Member Posts: 3
    thank you for ur great responce
    i got the solutuion :D
  • Options
    kmkaotkmkaot Member Posts: 261
    jlandeen wrote: »
    As an alternative solution to the one proposed above you may want to try using the TRANSFERFIELDS Function. The one requirement of using this function is that field types, lengths and ID's match (as it uses the Field No property to copy fields).
    IF Item.FINDSET THEN BEGIN
      REPEAT
        CLEAR(NewRecord);
        NewRecord.TRANSFERFIELDS(Item);
        NewRecord.INSERT;
      UNTIL Item.NEXT = 0;
    END;
    

    This function can be used to copy fields between record types that are not the same (e.g. use TransferFields to copy data from a Sales Line record to a Sales Inv. Line record).

    Check out the online documentation of TRANSFERFIELDS(Record) in Navision help.

    It will not work as there will be issue with Key
  • Options
    Jan87Jan87 Member Posts: 26
    @kmkaot what do you mean? When all ids, field types and lengths match and of course the primary key match where is the problem?
  • Options
    alvarotalvarot Member Posts: 1
    Caution for Primary Keys fields ;)
  • Options
    mohanragvmohanragv Member Posts: 2
    Guys if i have to transfer primary key data too and data already present in the table then please suggest some solution would be very thankful :smiley:
  • Options
    TallyHoTallyHo Member Posts: 383
    mohanragv wrote: »
    Guys if i have to transfer primary key data too and data already present in the table then please suggest some solution would be very thankful :smiley:

    Try this:
    IF Item.FINDSET THEN BEGIN
    REPEAT
    CLEAR(NewRecord);
    NewRecord.TRANSFERFIELDS(Item);
    //for update
    if not NewRecord.INSERT then
    NewRecord.modfy;
    //for insert only:
    if not NewRecord.INSERT then;
    UNTIL Item.NEXT = 0;
    END;
Sign In or Register to comment.