1 2 Previous Next 28 Replies Latest reply on Jan 22, 2013 2:33 PM by philmodjunk

    Problems dublicating records

    hanstrager

      Title

      Problems dublicating records

      Post

           I have a bit of a problem.

           Im trying to make a dublicate record button on one of my layouts (technical sheet2), but everytime I dublicate it seems everything gets duplicated except for things that’s in my 4 different portals.

           My scripting skills a very limited so I’m hoping someone can help me make a script so the whole record gets dublicated. I have the feeling it has something todo with the items in my lineitems that dosen't get copied or something, but not sure how to approach it.

           I’ve attached my relationship graph, and it’s records in technical sheet I want to dublicate…

      Picture_13.png

        • 1. Re: Problems dublicating records
          philmodjunk

               The data in your portals are in records other that the technical data sheet table. Thus duplicating the technical data sheet record does not also duplicate them. Your Duplicated record will still auto-enter a new value in xTechnical sheet_ID and it will not match to any records in the three table occurrences shown in your screen shot given this new value.

               If you want to also duplicate the related records so that they also appear in your portals when you duplicate the parent record, you need a script that correctly loops through the records in these related table(s).

               See this thread for an example script: Duplicating Bill Of Materials (duplicating portal line items)

               Be sure to look at the very last version of this script near the end of the script. The first script has a flaw fixed later in the thread.

          • 2. Re: Problems dublicating records
            hanstrager

                 before I start, how do adress the problem of having 4 BOM's - do I run this script 4 times..?

                  

                 #Starts from BOM based layout
                 Freeze Window
            Set variable [$RecordNumber ; Value: Get ( RecordNumber ) ]
                 Duplicate Record
                 Set Variable [$BOMID ; BOM::kp_BOMID]
            Go To Record/Request/Page [$RecordNumber]
                 If [ Not IsEmpty ( LineItems::kf_BOMID ) /* there are line items to duplicate */]
                    Go To Related Record [Show only related records; From table: lineItems; Using layout: "lineItems" (lineItems)]
                    Go To Record/Request/Page [first]
                    Loop
                       Duplicate Record
                       Set Field [ LineItems::kf_BOMID ; $BOMID]
                       Omit Record
                       Go To Record/Request/Page [first]
                       Omit Record
                       Exit loop If [ get ( FoundCount ) = 0 ]
                    End Loop
                    Go To Layout [original layout]
                    Go To Record/Request/Page [Last]
                 End IF

            • 3. Re: Problems dublicating records
              philmodjunk

                   Yes, the part that duplicates the set of related records will need to be run 4 times--each via a different relationship and table occurrence, but not the part that duplicates the parent record.

              • 4. Re: Problems dublicating records
                hanstrager

                     I've tried with the following:


                     Freeze Window
                     Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                     Duplicate Record/Request
                     Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                     Go to Record/Request/Page [ $RecordNumber ]
                     If [ not IsEmpty(Line Items::TechSheetID_FK) ]
                     Go to Related Record [ From table: “Line Items”; Using layout: “Line Items” (Line Items) ]
                     Go to Record/Request/Page
                     [ First ]
                     Loop
                     Duplicate Record/Request
                     Set Field [ Line Items::TechSheetID_FK; $TECHSHEETID ]
                     Omit Record
                     Exit Loop If [ Get ( FoundCount )=0 ]
                     End Loop
                     Go to Layout [ original layout ]
                     Go to Record/Request/Page
                     [ Last ]
                     End If
                      

                     when i press the button a dialog box pops asking me to specify a number. asking to go to a record out of my current records +1 - if that makes sense and then it starts uncontrolled to copy records into my lineitems... what do I do wrong..?

                • 5. Re: Problems dublicating records
                  philmodjunk

                       Go to Record/Request/Page [ $RecordNumber ]

                       should be:

                       Go to Record/Request/Page [ no dialog; $RecordNumber ]

                       Click the "Perform without dialog" option for this script step.

                       You are missing the second omit record step after returning to the first record in the set of line item records. This step omits the record just used to generate the new duplicate. If it is not omitted, the script duplicates the same line items record over and over again. And your script needs to use Go TO Record/Request/Page [FIRST] not [LAST].

                  • 6. Re: Problems dublicating records
                    hanstrager

                         sorry did not see I was missing that. But it still does some stuff im not really sure about. everythime i copy a record it multiplies my line items with 2. so if i have  a record with 2 lineitems in my portal and copy it once it becomes 4 and copy it twice it becomes 8 instead of 6 and so on... aswell it seems to also copy them into my portal... what am I doing wrong..?

                         Freeze Window
                         Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                         Duplicate Record/Request
                         Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                         Go to Record/Request/Page [ $RecordNumber ]
                         [ No dialog ]
                         If [ not IsEmpty(Line Items::TechSheetID_FK) ]
                         Go to Related Record [ From table: “Line Items”; Using layout: “Line Items” (Line Items) ]
                         Go to Record/Request/Page [ First ]
                         Loop
                         Duplicate Record/Request
                         Set Field [ Line Items::TechSheetID_FK; $TECHSHEETID ]
                         Omit Record
                         Go to Record/Request/Page [ First ]
                         Omit Record
                         Exit Loop If [ Get ( FoundCount )=0 ]
                         End Loop
                         Go to Layout [ original layout ]
                         Go to Record/Request/Page [ Last ]
                         End If
                          

                    • 7. Re: Problems dublicating records
                      hanstrager

                           I don't know if it has anything to do with a i have button which is adding my line items to my portal..?

                      • 8. Re: Problems dublicating records
                        philmodjunk

                             I see no errors in your script or in your relationship.

                             Are you on a layout based on Technical Sheet 2 when you perform this script?

                             Is Technical Sheet 2::xTechnical Sheet_ID an auto-entered serial number?

                        • 9. Re: Problems dublicating records
                          hanstrager

                               yes i perform the script from Tchnical Sheet 2

                               yes Technical Sheet 2::xTechnical Sheet_ID is an indexed auto-entered serial.

                                

                               Im not entirely sure what happens, but to me it seems it adds all the records from my line items into my portal...

                               can it have anything to do with me having "Line items 2" or a button on the layout to add rows in the portal that somehow interferes with the script..?

                          • 10. Re: Problems dublicating records
                            philmodjunk

                                 None of those should be a factor.

                                 The portal is a portal to Line Items?

                                 Is this what you see in the original Technical Sheet record?

                                 What do you see in that portal for the duplicated record?

                                 If you have FileMaker Advanced, I suggest enabling the script debugger and then testing this script so that you can step through it line by line and see what is going on.

                                 If you do not have advanced, you might try adding a pause/resume step inside the loop so that you can inspect things and then conintue the script to watch it step through the records being duplicated.

                            • 11. Re: Problems dublicating records
                              hanstrager

                                   yes the portal is a portal to line items

                                   not sure what you mean by the underneath:

                                   "Is this what you see in the original Technical Sheet record?"

                                   "What do you see in that portal for the duplicated record?"

                                    

                                   I went through with the script debugger. And basically it goes through:

                                   Duplicate Record/Request
                                   Set Field [ Line Items::TechSheetID_FK; $TECHSHEETID ]
                                   Omit Record
                                   Go to Record/Request/Page [ First ]
                                   Omit Record
                                   Exit Loop If [ Get ( FoundCount )=0 ]

                                   the amount of times there's records in Line Items, so it's double. Does that help anything..?

                              • 12. Re: Problems dublicating records
                                hanstrager

                                     Is there no way anyone can help me out with this problem?

                                     Without knowing to much about scripts it seems  (when run through script bugger) Get ( FoundCount )=0 dosen’t work properly and dosen’t have the script exit the loop, before it has duplicated all my line items, instead of only the ones in my portal.

                                     I’m new to filemaker and this is my first database, so don’t know much about scripting, where is the places in the script that can cause this problem...?

                                     Is there another way of duplicating the records with a portals..? will it help to make the script again?

                                     Sorry just being a bit desperate to have this script working…

                                • 13. Re: Problems dublicating records
                                  philmodjunk

                                       When you run this script it creates a new record in the parent table--the table on which your layout is based.

                                       That makes for two records--the original that was the current record when you first performed the script and the duplicate parent record produced by the script. When you tell me that you are seeing both the original and duplicated line item records, I need to know whether this is from the context of the original parent record or the new duplicate created by the script or both.

                                       My best guess is that you see the same "double set" of records in the portal from both the original and duplicate parent records. If so, I believe that I know what the problem is.

                                  • 14. Re: Problems dublicating records
                                    hanstrager

                                         im not sure how I can check if it's both showing the records from the parent record and a copied set. But it seems like it's what happening since it's showing exactly the same from the record it has been copied from and then exactly a the same set straight after...

                                    1 2 Previous Next