easy RecordRef Insert problem

mnewmediamnewmedia Member Posts: 13
edited 2013-10-11 in NAV Three Tier
Hello togheter,
I have two tables 50000 and 50001 both has the fields "Name" and "Description".
I wanna Copy all records from the the first table to the second, but it works only with the Field "Name". somebody knows why?
RecordRef1.OPEN(50000);
RecordRef1.FINDFIRST;
RecordRef2.OPEN(50001);
RecordRef2.INIT;

IF RecordRef1.FIND('-') THEN REPEAT
   field1 := RecordRef1.FIELD(2); // works only with 1
   field2 := RecordRef2.FIELD(2); // works only with 1
   field2.VALUE := field1.VALUE;
   RecordRef2.INSERT;
UNTIL RecordRef1.NEXT = 0;
I get the Error (translated by me to english) "'table2' exists already. Identified Fields and Values: Name="
Any Ideas, Tipps?
Thanks
mnewmedia
NAV 2009 R2
NAV 2013 R2

Comments

  • Nagaraju17Nagaraju17 Member Posts: 12
    Why not use Transferfields function......
    .....................
  • mnewmediamnewmedia Member Posts: 13
    Because later i need to use RecordRef variable and TRANSFERFIELDS only works with a normal Record Variable...
    mnewmedia
    NAV 2009 R2
    NAV 2013 R2
  • KishormKishorm Member Posts: 921
    The problem is you are not copying all fields across but just one field. This works for your Name field as this must be your primary key and doesn't work for the Description field because in that instance you are not setting the primary key field in the record being inserted so it is always blank. Put a loop in there to copy BOTH fields and it will work.
  • mnewmediamnewmedia Member Posts: 13
    Put a loop in there to copy BOTH fields and it will work
    Can you provide a small example for that?
    Or do you mean i have to do it like that:
       IF RecordRef1.FIND('-') THEN REPEAT
          field1 := RecordRef1.FIELD(1);
          field2 := RecordRef2.FIELD(1);
          field2.VALUE := field1.VALUE;
          field1 := RecordRef1.FIELD(2);
          field2 := RecordRef2.FIELD(2);
          field2.VALUE := field1.VALUE;
          RecordRef2.INSERT;
       UNTIL RecordRef1.NEXT = 0;
    
    And what if let's say i already copied Field 1 (Name) and wanna later copy only the Field 2 (Description)? Do i have to change the Primary Key, or is there an other way?
    mnewmedia
    NAV 2009 R2
    NAV 2013 R2
Sign In or Register to comment.