Problem in Renaming a Record(Kine)

Vineeth.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.
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
Vineeth.R
0
Comments
-
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?0 -
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;
RegardsDo you make it right, it works too!0 -
sh***, the coffee break was to long.Do you make it right, it works too!0
-
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.R0 -
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.0 -
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);
0 -
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 :!:0 -
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.R0 -
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.R0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions