Selected records not in current key order

Steve_Contris
Member Posts: 114
I am using Navision 2009 - I am creating a report that will report and delete customers with duplicate email addresses. The report is fairly simple and has one DataItem: Customer. I am going through the Customer table in order of No. such that the oldest versions of these duplicate E-mail customers will be found first. I want to keep the oldest version and delete the rest.
I have added a key to the Customer file by Email.
In the report I have global record variable of the Customer table called DupCust.
In the OnAfterGetRecord trigger I do this:
DupCust.SETRANGE("E-Mail",Customer."E-Mail") // filter to only records that match the Customer.E-Mail
DupCust.SETCURRENTKEY("No."); // put any records that satisfy the filter in order of No.
However, I am finding that the DupCust records loaded this way are not always in the order of "No."
I have tried all three of these to select what should be the first in order of "No.":
DupCust.GET(Customer."No."); this always find what should be the first by No. but sometimes DupCust.NEXT returns 0
DupCust.FIND('-'); this sometimes selects the first by No. - if not, then DupCust.NEXT returns 0
DupCust.FINDFIRST(); this sometimes selects the first by No. - if not, then DupCust.NEXT returns 0
So what seems to be happening is that sometimes the selected records are in "No" order but not always. For instance, I may end up with 2 DupCust records with matching E-Mails having No. 100066 and 100074 but I end up with No. 100074 first and the DupCust.NEXT finds no record - returns 0;
Am I not setting the order of these selected records correctly?
thanks for any help here...
I have added a key to the Customer file by Email.
In the report I have global record variable of the Customer table called DupCust.
In the OnAfterGetRecord trigger I do this:
DupCust.SETRANGE("E-Mail",Customer."E-Mail") // filter to only records that match the Customer.E-Mail
DupCust.SETCURRENTKEY("No."); // put any records that satisfy the filter in order of No.
However, I am finding that the DupCust records loaded this way are not always in the order of "No."
I have tried all three of these to select what should be the first in order of "No.":
DupCust.GET(Customer."No."); this always find what should be the first by No. but sometimes DupCust.NEXT returns 0
DupCust.FIND('-'); this sometimes selects the first by No. - if not, then DupCust.NEXT returns 0
DupCust.FINDFIRST(); this sometimes selects the first by No. - if not, then DupCust.NEXT returns 0
So what seems to be happening is that sometimes the selected records are in "No" order but not always. For instance, I may end up with 2 DupCust records with matching E-Mails having No. 100066 and 100074 but I end up with No. 100074 first and the DupCust.NEXT finds no record - returns 0;
Am I not setting the order of these selected records correctly?
thanks for any help here...
What would Elvis do?
0
Comments
-
Why don't you try this:
DupCust.SETCURRENTKEY("E-Mail");
DupCust.SETRANGE("E-Mail",Customer."E-Mail");
DupCust.SETFILTER("No.",'<>%1', Customer."No.);
IF DupCust.FINDSET THEN DupCust.DELETEALL(); // considering the fact that you want to delete the duplicate records.0 -
Chinmoy wrote:Why don't you try this:
DupCust.SETCURRENTKEY("E-Mail");
DupCust.SETRANGE("E-Mail",Customer."E-Mail");
DupCust.SETFILTER("No.",'<>%1', Customer."No.);
IF DupCust.FINDSET THEN DupCust.DELETEALL(); // considering the fact that you want to delete the duplicate records.
That's a good idea - I will give it a try.
thanksWhat would Elvis do?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