Modifing a primary key value...

deepbluedeepblue Member Posts: 152
Hello!

I would like to modify the value of a field which belongs to the primary key of a record. When I try to use MODIFY, error message appears saying that the record NewValue does not exist. How can I do it?

Thank You!

Answers

  • JedrzejTJedrzejT Member Posts: 267
    Try

    rec.GET(primarykeyfield1,primarykeyfield2,..)
    rec.RENAME(PrimaryKeyfield1NewValue,PrimaryKeyfield2NewValue,..)
  • deepbluedeepblue Member Posts: 152
    I'm trying to modify many records, but RENAME only works for the first record! ](*,)
        WITH Record1 DO BEGIN
          RESET;
          SETRANGE(Field1,'Exemple');
          SETRANGE(Field2,0);
          if FIND('-') then
          REPEAT
            RENAME(Field1,NewField2,Field3); 
          UNTIL NEXT = 0;
        END;
    
  • girish.joshigirish.joshi Member Posts: 407
    deepblue wrote:
    I'm trying to modify many records, but RENAME only works for the first record! ](*,)
        WITH Record1 DO BEGIN
          RESET;
          SETRANGE(Field1,'Exemple');
          SETRANGE(Field2,0);
          if FIND('-') then
          REPEAT
            RENAME(Field1,NewField2,Field3); 
          UNTIL NEXT = 0;
        END;
    

    Try this instead:
    Rec1.reset;
    Rec1.setrange(field1,'exemple') ;
    Rec1.setrange(field2,0) ;
    if Rec1.find('-') then 
      repeat
        Rec2 := Rec1 ;
        Rec2.rename( field1, newfield2, field3 ) ; 
      until Rec1.next = 0 ; 
    
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    Strange. It should work. However, I assume that renaming is not a part of your standard business process but a one-time only correction, you could write code with filevar.CREATE, filevar.TEXTMODE(TRUE),filevar.WRITE('text'); to generate hardcoded code to a textfile and copy-paste it into Navision, generating code like:

    CLEAR(Record);
    Record.GET('B112');
    Record.RENAME('A134');

    Ugly, but it works as a one-time solution.
  • zeninolegzeninoleg Member Posts: 236
    Looks like you are trying to insert more then 1 record with the same Primary key. If you have 3 fields in the primary key then based on your code you have to change value of the Field3 before RENAME.
    Best Regards,
    Oleg
Sign In or Register to comment.