Problem in Renaming a Record(Kine)

Vineeth.RVineeth.R Member Posts: 121
Dear Friends,

I am trying to change the employee number(No.) field in the Employee card,when the number is changed the (No.) field in the Resource table should also change which is the primary key field of that table. i used the following code but i face an error when i try to change it for the second time and after that.
i gave this code in the No. (Onvalidate) of Employee Table


IF Rec."No." <> xRec."No." THEN BEGIN
lvFound := FALSE;
lvResource.RESET;
IF lvResource.FIND('-') THEN BEGIN
REPEAT
IF lvResource."No." = xRec."No." THEN BEGIN
lvResource.RENAME(Rec."No."); //some issue here
lvFound := TRUE;
END;
UNTIL (lvResource.NEXT = 0) OR (lvFound);
END;


the problem comes where RENAME is used. I tried giving commit and all but no use. it says "Another user has modified the definition of the Field Table after the activity was started. START AGAIN" and this same error keeps on coming when ever i click anyware or go to employee table. i need to start the navision window again.

One more thing this error occurs only when i use FINSQL, in local the rename works without any error. how to solve this.
Thanks and Regards
Vineeth.R

Comments

  • kinekine Member Posts: 12,562
    1) Why you are looping through all resources when you know the No.?
    2) Renaming record which is used to loop through some record set is bad. After renaming, the cursor is in undeffined state and you can get into neverending loop or end the loop to early...
    3) Which client version you are using?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    u know the record and use a loop :?:
    if you change fields in a record which are in the filter, it is better to modify a second recordvariable with the same record. like following:
    setfilter() .....
    repeat
      Rec2.get(YourREcord.PrimaryKey);
      Rec2.Field := NewValue;
      Rec2.modify;
    until YourRecord.next 0 0;
    

    Regards
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    sh***, the coffee break was to long.
    Do you make it right, it works too!
  • Vineeth.RVineeth.R Member Posts: 121
    Dear Friends,

    yes i tried to find the record and the renaming is working but only for the first record in the recordset found. its not renaming the rest of the record and coming out of the loop.Please help

    here is my code in the employee Card forms "no." fields onvalidate trigger, i want to rename the corresponding employee qualification's Employee number also.


    lvEmployeeQualification.RESET;
    lvEmployeeQualification.SETRANGE("Employee No.",xRec."No.");
    IF lvEmployeeQualification.FIND('-') THEN BEGIN
    MESSAGE(FORMAT(lvEmployeeQualification.COUNT));//12 records found
    REPEAT
    lvEmployeeQualification.RENAME(Rec."No.", lvEmployeeQualification."Line No.");//renamed first one then jumped out of the loop
    UNTIL lvEmployeeQualification.NEXT = 0;
    END;
    Thanks and Regards
    Vineeth.R
  • krzychub83krzychub83 Member Posts: 120
    It's seams that the form is looking for an old rec. I had it when I was deleting current record of the form from the CU. What do You think about:
    CurrForm.Update(False);
    (on the end of this code?)

    Maybe it will help.
  • krzychub83krzychub83 Member Posts: 120
    edited 2008-06-06
    Something like this (I'm new on Nav, so there maybe some mistakes):
      THERE WAS A VERY BAD CODE HERE... SHAME OF ME...  
      I new I forget about something... Coffee :P
    
    AT THE FORM (OnValidate):
    CurrForm.Update(False);
    
  • kinekine Member Posts: 12,562
    1) Transferfields is not needed when copying between same record type...
    2) Just using second variable is not enough in newer versions of client. Best is to add records you need to rename into temporary table and then in loop go though this temp table and get real record and rename it... something like:
    lvEmployeeQualification.RESET;
    lvEmployeeQualification.SETRANGE("Employee No.",xRec."No.");
    IF lvEmployeeQualification.FINDSET THEN BEGIN
      REPEAT
        lvTempEmployeeQualification := lvEmployeeQualification;
        lvTempEmployeeQualification.INSERT;
      UNTIL lvEmployeeQualification.NEXT = 0;
    END;
    
    IF lvTempEmployeeQualification.FINDSET THEN BEGIN
      REPEAT
        lvEmployeeQualification.GET(lvTempEmployeeQualification."Employee No.");
        lvEmployeeQualification.RENAME(Rec."No.", lvEmployeeQualification."Line No.");
      UNTIL lvTempEmployeeQualification.NEXT = 0;
    END;
    
    

    :!: And do not forget, that if you have correct TableRelation, you do not need any code to rename the records :!:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Vineeth.RVineeth.R Member Posts: 121
    Hi Kine

    thank you . i was able to solve the issue using Temporary variable concept...

    The same coding which now i gave in form's - "No." fields onvalidate worked well..
    but when i tried the same in table's "no." fields onvalidate it gave me error saying

    "another user modified the record. start again" why is it so??????
    Thanks and Regards
    Vineeth.R
  • Vineeth.RVineeth.R Member Posts: 121
    Hi Kine

    thank you . i was able to solve the issue using Temporary variable concept...

    The same coding which now i gave in form's - "No." fields onvalidate worked well..
    but when i tried the same in table's "no." fields onvalidate it gave me error saying

    "another user modified the record. start again" why is it so??????[in finsql]









    kine wrote:
    1) Transferfields is not needed when copying between same record type...
    2) Just using second variable is not enough in newer versions of client. Best is to add records you need to rename into temporary table and then in loop go though this temp table and get real record and rename it... something like:
    lvEmployeeQualification.RESET;
    lvEmployeeQualification.SETRANGE("Employee No.",xRec."No.");
    IF lvEmployeeQualification.FINDSET THEN BEGIN
      REPEAT
        lvTempEmployeeQualification := lvEmployeeQualification;
        lvTempEmployeeQualification.INSERT;
      UNTIL lvEmployeeQualification.NEXT = 0;
    END;
    
    IF lvTempEmployeeQualification.FINDSET THEN BEGIN
      REPEAT
        lvEmployeeQualification.GET(lvTempEmployeeQualification."Employee No.");
        lvEmployeeQualification.RENAME(Rec."No.", lvEmployeeQualification."Line No.");
      UNTIL lvTempEmployeeQualification.NEXT = 0;
    END;
    
    

    :!: And do not forget, that if you have correct TableRelation, you do not need any code to rename the records :!:
    Thanks and Regards
    Vineeth.R
Sign In or Register to comment.