Rename a record

steallosteallo Member Posts: 21
I have to rename the Reason Code record, setting the
NewPK := 'PF' + OldPK

Not work using report or repeat until on the record.It work only on the first record retrived and the exit without any error....
it's normal? :-k

Thanks in Advance

Comments

  • satraja2004satraja2004 Member Posts: 45
    Hi,

    Could u explain in detail what u want to do?

    If possible could u paste the sample code and the trigger name where u have done the coding...
    Thanks & Regards

    Raja.B
  • steallosteallo Member Posts: 21
    IF ReasCode.FIND('-') THEN
    REPEAT
    IF COPYSTR(ReasCode.Code, 1, 2) <> 'PF' THEN BEGIN
    NewCode := 'PF' + ReasCode.Code;
    ReasCode.RENAME(NewCode);
    END;
    UNTIL ReasCode.NEXT = 0;
  • MBergerMBerger Member Posts: 413
    This is probably becuase you are using the primary key as the sorting for the loop. The renamed record will becomes the last record in the table, so next will be 0.

    Example : say you have the codes 01, 02 and 03. Renaming the first one to PF01 will make the table 02, 03, and PF01. because you are still on the PF01 record, next will say it has reached the end of the table.
  • steallosteallo Member Posts: 21
    so maybe if i use another key for the record i'll solve the problem?
  • MBergerMBerger Member Posts: 413
    As long as you use a sorting that won't change the order of the records when you rename your record, you're set.
  • navuser1navuser1 Member Posts: 1,329
    Try this................

    Create a New report.
    Take one DataItem : Reason Code
    and write two line code....
    Reason Code - OnAfterGetRecord()
    IF COPYSTR(Code,1,2) <> 'navuser1' THEN
    RENAME('navuser1' +Code);
    Now or Never
  • kinekine Member Posts: 12,562
    Or you can just copy all records into TEMP variable based on same table and then go through this table in loop and rename the records in real table...
    if MyReasonRec.FINDSET then
    repeat
      MyTempReason := MyReasonRec;
      MyTempReason.INSERT;
    until MyReasonRec.NEXT=0;
    
    if MyTempReason.FINDSETthen
    repeat
      MyReasonRec.GET(MyTempReason.Code);
      MyReasonRec.RENAME('PK'+MyReasonRec.Code);
    until MyTempReason.NEXT=0;
    

    Do not forget that the MyTempReason is TEMPORARY variable. Of course, naming of the variables are just examples... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.