2 Replies Latest reply on Aug 5, 2014 8:55 AM by philmodjunk

    Help with loop logic, find duplicates



      Help with loop logic, find duplicates


           I have an import from a CSV with a product number and ID. I need to find the duplicates within the found set, so say if the records look like this:

      1.           Product_id=465
      3.           Product_id=465
      5.           Product_id=465
      7.           Product_id=500
      9.           Product_id=500
      11.           Product_id=500
      13.           Product_id=500

           I need to find the duplicates, except the first one and mark the first incident so I can export those ID's as a csv. I thought about a 'duplicate' field, then a loop to check to see if the current record Product_ID matches the previous, if so-put an 'X' in the duplicate field. If not, move to next record and check again. Maybe I'm tired, but the logic is driving me nuts.

           I thought about something like this:

           Set Variable [$$dup; Value:Product::ID]
           Go to Recore/Request/Page [Next]
           If [Product::Duplicate <> "x"]
           Else If [Product::ID=$$dup]
               Insert Text[Select,Product::Duplicate; "x"]
           End If
           Go to Record/Request/Page[Next]

           But I'm sure this wrong and not working. Any ideas?



        • 1. Re: Help with loop logic, find duplicates


               i am not sure if i fully understand what you need but if you want to remove duplicate records from foundset after import you can use relationship(see attached screen) a run script when in loop check if IsEmpty ( Duplicates::id ) and if true set some flag for example to 1. Then just do find every records with flag equals 1.

               I created file with example, you can see it here: https://www.dropbox.com/s/fohldyg8dxap5g1/Untitled.fmp12





          • 2. Re: Help with loop logic, find duplicates

                 There are several ways to remove duplicates, I prefer to import the data with duplicates into a table where field validation filters out the duplicates, it's often a faster way to set up what is often a "one time fix", but jlarmen mentions wanting to export this data to CSV, you can export such data with duplicates removed without any effort made to remove duplicates from your table if you sort your records to group them by the product id field and then specify the "group by" option when exporting the data. This option exports one row of csv data for each group of records instead of one row for each individual record.