Newbies ateles Posted April 13, 2005 Newbies Posted April 13, 2005 Hello, When importing records from one table to another I only want to keep unique entries. For example, if 100 records in Table A all have value "11" in field "Strata" then when imported into Table B, only one record for "11" should appear. I wrote the following script (which worked perfectly well in version 6) Import Records [ Source: "file:Homestead Dummy.fp7" ] Show All Records Sort Records [ Specified Sort Order: Strata::Stratum; ascending ][ Restore; No dialog ] Go to Record/Request/Page[ First ] Set Field [ Strata::Stratum Global; Strata::Stratum ] Go to Record/Request/Page[ Next ] Loop If [ Strata::Stratum = Strata::Stratum Global ] Delete Record/Request[ No dialog ] Else Set Field [ Strata::Stratum Global; Strata::Stratum ] Go to Record/Request/Page[ Next; Exit after last ] End If End Loop Using pause functions I am certain that the script runs properly up until the exiting command. But then it doesn't seem to actually exit the loop. I can see the program go back to my first record and delete it. As I mentioned before, this exact script works fine in earlier versions. Is there something different about scripting loops in Version 7? Any thoughts on what might be going wrong? Thank you!
quillpro Posted April 13, 2005 Posted April 13, 2005 Chances are the the last record in your If script is evaluating true. If so you skip over the exit after last command in the Go to Record step. If [ Strata::Stratum = Strata::Stratum Global ] # if the last record is ture then you do not specify a exit step here. Delete Record/Request[ No dialog ] # Else Set Field [ Strata::Stratum Global; Strata::Stratum ] # only if your last is false does your exit step happen. Go to Record/Request/Page[ Next; Exit after last ] # End If End Loop Does that make sense?
Newbies ateles Posted April 13, 2005 Author Newbies Posted April 13, 2005 not sure that makes sense i've imported all records and then am using the global field to compare records to one another and only keep one copy of each record containing a given value in field "strata" so, after the if, if it is equal then the command is to delete the one it's being compared to. Then if it isn't equal, it will reset the global field to that new value. that part all works fine, i can see it delete records and reset the value in the Global field, just before the exit step - i have one record for each unique "strata" so the error is only with that last step.
comment Posted April 13, 2005 Posted April 13, 2005 The problem you have here is that there is no exit provided on the true part of the loop. Let's take an example with 4 records having the following values: 1 a 2 b 3 c 4 c When the script gets to record #3, the global is set to "c". When the script gets to record #4, the condition global = local is true, and record #4 is deleted. Since #4 was the last record in the found set, the current record is now record #3. The condition global = local is also true for record #3, so this record is deleted as well. So, if the last record is not unique, all the records with the same value will be deleted. In any version.
Ender Posted April 13, 2005 Posted April 13, 2005 Not sure if it works for your situation, but in the import dialog, there's an option to update matching records in the found set. With this option, and 'Add remaining data' selected, you should be able to match on Strata and have duplicates automatically filtered out.
Recommended Posts
This topic is 7166 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now