Selected records not in current key order

Steve_ContrisSteve_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...
What would Elvis do?

Comments

  • ChinmoyChinmoy Member Posts: 359
    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.

    :)
  • Steve_ContrisSteve_Contris Member Posts: 114
    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.

    thanks
    What would Elvis do?
Sign In or Register to comment.