Filtering and Updating the same Field Issue.

vivek4121
Member Posts: 165
Hi All,
I need to update the Salesperson code in the Contact table, I have used the below code :
There are 4 records within the filter, which i need to modify. But my concern is it only updates only the first record.
And When I Removed the "Contact.SETCURRENTKEY("Salesperson Code");" Line of code, then it updates all the records.
I did't understand the logic behind that.
Can anyone help?
Thanks in advance.
I need to update the Salesperson code in the Contact table, I have used the below code :
Contact.RESET; Contact.SETRANGE("Salesperson Code",'3803'); Contact.SETCURRENTKEY("Salesperson Code"); IF Contact.FINDSET(TRUE,TRUE) THEN BEGIN REPEAT Contact.VALIDATE("Salesperson Code",'5189'); Contact.MODIFY; UNTIL Contact.NEXT = 0; END;
There are 4 records within the filter, which i need to modify. But my concern is it only updates only the first record.
And When I Removed the "Contact.SETCURRENTKEY("Salesperson Code");" Line of code, then it updates all the records.
I did't understand the logic behind that.
Can anyone help?
Thanks in advance.
0
Comments
-
The issue that you are updating facing is that you are modifying the field you also are sorting on using the same variable. This way SQL Server qoes astray. You should use a second variable based on the same table, e.g. Contact2 and write your code as following:
Contact.RESET; Contact.SETRANGE("Salesperson Code",'3803'); Contact.SETCURRENTKEY("Salesperson Code"); IF Contact.FINDSET(TRUE,TRUE) THEN BEGIN REPEAT Contact2 := Contact; Contact2.VALIDATE("Salesperson Code",'5189'); Contact2.MODIFY; UNTIL Contact.NEXT = 0; END;
0 -
If you looping a table and you change on the fly that can , best solution is to put the records in a temptable and then read the temptable and change the records in your real table.
But in this case, it is even easier:Contact.RESET; Contact.SETCURRENTKEY("Salesperson Code"); Contact.SETRANGE("Salesperson Code",'3803'); Contact.MODIFYALL("Salesperson Code",'5189');
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:If you looping a table and you change on the fly that can , best solution is to put the records in a temptable and then read the temptable and change the records in your real table.
But in this case, it is even easier:Contact.RESET; Contact.SETCURRENTKEY("Salesperson Code"); Contact.SETRANGE("Salesperson Code",'3803'); Contact.MODIFYALL("Salesperson Code",'5189');
0 -
Depends if you need to trigger the code or not.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Also don't forget that the RunTrigger parameter of MODIFYALL relates to calling the OnModify trigger of the record and not the OnValidate trigger of the field.0
-
Thanks for the Replies.
Can you guys please elaborate this term a bit more "SQL Server goes astray"?0 -
vivek4121 wrote:Can you guys please elaborate this term a bit more "SQL Server goes astray"?
Hope this makes sense.0 -
=D> Thanks a lot.0
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