MarkWilson Posted November 20, 2003 Posted November 20, 2003 I am using a script, in the master file, to duplicate a set of records in a sub file to another record in the master file. Because I don't always want all of the records to be duplicated, I use a toggle (Toggle_1) to select the duplicate items. The master script finds the related records, via Go To Related Record [show only related records], then calls a sub-script in the sub file to set all items to duplicate (Toggle_1 = 1). The user then has the option, via a portal, to remove the unwanted items. This part works fine. The master script then calls a second sub-script to duplicate the remaining records. The problem is that in the set of duplicate items some of the records are skipped over. Of the 804 records I have, 112, consistently the same records, being skipped. If I run only the duplicate sub-script again more will be duplicated. I can eventually get all of the records to duplicate. It may duplicate 1 or it may duplicate 30 or some number in between each time it is repeated. I tried a small found set and added a pause to the loop to check after each record for an error. It returned nothing. Duplicate Sub-Script. Enter Browse Mode Perform Script [sort] Go To Record/Request/Page [First] Loop If [Toggle_1 = 1] Set Field [Toggle_1 , ""] Duplicate Record/Request Set Field [New_Master_Record_# , global_New_Master_Record_#] End If Go To Record/Request/Page [Next, Exit after last] End Loop I also tried replacing the If Toggle_1 = 1 with a find of the same to find only the items to to be duplicated. It returned the same result.
BobWeaver Posted November 20, 2003 Posted November 20, 2003 The problem with duplicating records while in a loop is that you don't know for sure where the duplicated record will go. If the file is unsorted, then the duplicate will be at the very end of the found set. If the file is sorted, then it could end up in any number of places. And the duplicate becomes your current record, so the next time through the loop, you will continue on with whatever record follows the duplicate, wherever that may be (and likely skipping a bunch of records). I prefer to have the file unsorted, so that the duplicate goes to the end. Before you duplicate the record, set some global field to the current record number so that you can keep track of where you are. Then immediately after creating it, omit the duplicate so you don't encounter it again. Finally, go to the record number stored in the global and continue on with your loop.
LaRetta Posted November 20, 2003 Posted November 20, 2003 Hi Mark, I think I might approach this a bit differently. Using a toggle (record marking) can cause problems in multi-user mode. So if you're multi-user (or ever plan to be), I'd suggest you resolve this by using a global multiline to store your UniqueIDs. And then allow Users to remove any records they wish and then proceed with your duplication process. If you don't want to worry about this issue and, since your existing process works okay now, you can just skip down to the Duplication script. As always, back up first ... After finding your set of records to duplicate, write their IDs to a global (text) field in your Main db (gSelected) as follows: Go to Record/Request/Page [First] Set Field [gSelected, UniqueID] Freeze Window Loop Go to Record/Request/Page [Next, Exit after last] Set Field [gSelected, gSelected & "
MarkWilson Posted November 21, 2003 Author Posted November 21, 2003 Thanks Bob, Taking out the sort worked perfectly. I can't say as I understand why because the records that would missed more often then not were in the middle of the found set and the last items would duplicate as requested. I am currently working though LaRetta's solution as well to see if I can prevent future trouble in my multi-user environment. Thanks.
LaRetta Posted November 21, 2003 Posted November 21, 2003 Hi Markus, It appears that I was a bit sloppy - I try very hard not to be ... Remove the first two lines of the Duplication script. I had already mentioned in the sentence above to do that. Your Duplication script (which would begin with "Go To Record/Request/Page" should reside in your related database. LaRetta
Oldfogey Posted November 21, 2003 Posted November 21, 2003 I ran into the same problem a while back and came up with a totally different solution which I use quite frequently. Once you have identified the records you want to duplicate, make them your found set. Export them and import them. Bingo!
MarkWilson Posted November 21, 2003 Author Posted November 21, 2003 Thank you, LaRetta. That works great. It will also help solve my next problem of a found set in a filtered portal and print set. I added one step to make it work for the next record in the portal sort. If [PatternCount("
LaRetta Posted November 21, 2003 Posted November 21, 2003 Hi Markus, Learning to write to a multiline (in sets or one at a time) and remove it again has been the most valuable thing I've learned about FM. It took a while to wrap my brain around the concept but it was certainly well worth the sweat. I'm sure I still have much to learn about the forumulas, however. I thank Ray (CobaltSky) for providing a website full of examples using it. It can be used for hundreds of things (as you've already seen), while maintaining each Users selections! Possibilities for multilines pop up every day and it's absolutely perfect for establishing a left key in a relationship on the fly - or to hold a set of IDs to work with as a list (in which you can then remove each one as finished)! The only limit is your imagination (and possibly the 64k limit). LaRetta
Recommended Posts
This topic is 8019 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