AnsweredAssumed Answered

Duplicate multiple records a specific number of times (i.e., for a label)

Question asked by sfishman@ou.edu on Apr 13, 2015
Latest reply on Apr 14, 2015 by sfishman@ou.edu

Title

Duplicate multiple records a specific number of times (i.e., for a label)

Post

I need help in creating a script to duplicate records a specific number of times for labels according to a record count.  I am working with a collection of objects and each object needs to have its own label.  For example, say I have a bag (x) with 4 objects and another bag (y) with 2 objects.  (another way to phrase it is Bag x has a count of 4 and bag y has a count of 2).  X will a total of 4 labels and y will need a total of 2 labels.

I created a label database file where I am exporting the information (to safeguard the primary database).  The label database only has two fields: Number of Records Needed (equivalent to record count) and LabelName. 

I tried to follow the instructions in the post How To Create A Specific Number Of Duplicate Records.  I added the fields listed in the script, but it is not working.  I work with >1000 records in each collection with a random number of records needing to be duplicated, so it is not feasible to individually duplicate them.

What changes do I need?

Set Error Capture [ On ]
Replace Field Contents [ CatalogTbl::RecordID ; Replace with serial numbers: Entry option values ; Initial value: 225 ; Increment value: 1 ][ No dialog ; Update Entry Options ]

Go to Record/Request/Page [ First ]

Copy [ CatalogTbl::RecordID ][ Select ]

Enter Find Mode [ ]
Paste [ CatalogTbl::RecordID ][ Select ]

Perform Find [ ]

#COMMENT: The script steps above prepare our database to create duplicates. So that the solution will run from beginning to end without

interruption, we have Set Error Capture to On. This will prevent any error messaging from FileMaker Pro to appear while the script is

running. It will then find all of the records to be duplicated.

Each record must have a unique ID. This is what our 'Replace Field Contents' step is doing. Once each record has its unique ID, we will copy the

number from our ‘Record Number’ field and perform a find for the record which has that number. This will make the first record the only

record in our found set.

Go to Record/Request/Page

[ First ]

Set Field [ CatalogTbl::Global Match for Records ; 1 ]

Set Field [ CatalogTbl::Original Marker ; "X" ]

Set Field [ CatalogTbl::Global Match for Duplicates ; "1" ]

Loop

If [ IsEmpty ( CatalogTbl::Amount of Duplicates )=0 and CatalogTbl::Amount of Duplicates CatalogTbl::Global Match for

Duplicates ]

Duplicate Record/Request

#Comment: The script steps above will go to the first record in our found set. The found set should be only one record. We then will mark

the record as our original with an 'X'. We will then set our field called 'Global Match For Records' to the 'Record Number' number

plus 1. This number is the unique ID of the next record. Our Set Field script then sets our 'Global Match For Duplicates' field to the

number 1 for the purpose of comparing this number to the number found in our 'Amount of Duplicates' field. If the numbers do not

match, a duplicate record will be created.

Clear [ CatalogTbl::Original Marker ]

[ Select ]

Set Field [ CatalogTbl::Global Match for Duplicates ; CatalogTbl::Global Match for Duplicates+1 ]

Else

Set Field [ CatalogTbl::Global Match for Records ; 1 ]

Copy [ CatalogTbl::Global Match for Records ]

[ Select ]

Enter Find Mode [ ]

Paste [ CatalogTbl::RecordID ]

[ Select ]

Perform Find [ ]

Go to Record/Request/Page

[ First ]

Set Field [ CatalogTbl::Original Marker ; "X" ]

Set Field [ CatalogTbl::Global Match for Records ; CatalogTbl::Global Match for Records+1 ]

If [ Get(FoundCount)=0 ]

Show All Records

Exit Script [ ]

End If

 

 

 

Outcomes