14 Replies Latest reply on Jun 12, 2014 12:06 PM by hanstrager

    Dublicate record

    hanstrager

      Title

      Dublicate record

      Post

           2 minor things in my database have been annoying me for a very long time, but i'm not sure how to fix it.

           I have a database where I quite often dublicate records. I use the following script:

           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 Fabric::TechSheetID_FK) ]
           Go to Related Record [ From table: “Line Items Fabric”; Using layout: “LINE ITEMS Fabrics” (Line Items Fabric) ]
           [ Show only related records ]
           Go to Record/Request/Page [ First ]
           Omit Record
           Exit Loop If [ Get ( FoundCount )=0 ]
           End Loop
           Go to Layout [ original layout ]

           My first problem is when I have dublicated a record I want automatically to go to this new record instead of staying in the old record. is there a way to do that?

           Then I have a few Radio button sets, which all have auto enter data, (since these can't stay empty), but when I copy my record these radio button reverts back to my auto enter data. Is there a way to have the radio buttons stay the same as my dublicated record..?

        • 1. Re: Dublicate record
          philmodjunk

               Usually the duplicated parent record is the last record in your found set. If so, you could add a go to record/request/page [last] step to the end of this script. If, this new record is not the last record (perhaps you have a automatically updating sort order that put it in a different position in the found set), you could add Set variable [$NewRecordNumber ; value: Get ( RecordNumber ) ] immediately after the First Duplicate Record/Request step and then use that variable in your final go to record/request/Page step to go to it after all is done here.

          • 2. Re: Dublicate record
            hanstrager

                 Just realised I needed to add some more line items onto my script - Did it like this, but it dosen't take me to the newly dublicated record:

                 Freeze Window
                 Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                 Duplicate Record/Request
            Set Variable [ $NewRecordNumber; Value:Get(RecordNumber) ]
                 #The 'set variable' for go to dublivated record
                 Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                 Go to Record/Request/Page [ $RecordNumber ]
                 [ No dialog ]
                 If [ not IsEmpty(Line Items Fabric::TechSheetID_FK) ]
                 Go to Related Record [ From table: “Line Items Fabric”; Using layout: “LINE ITEMS Fabrics” (Line Items Fabric) ]
                 [ Show only related records ]
                 Go to Record/Request/Page
                 [ First ]
                 Loop
                 Duplicate Record/Request
                 Set Field [ Line Items Fabric::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 [ $recordNumber ]
                 [ No dialog ]
                 End If
                 If [ not IsEmpty(line items zip::xZip_ID) ]
                 Go to Related Record [ From table: “line items zip”; Using layout: “LINE ITEMS zip” (line items zip) ]
                 [ Show only related records ]
                 Go to Record/Request/Page
                 [ First ]
                 Loop
                 Duplicate Record/Request
                 Set Field [ line items zip::xtechsheetFK; $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 [ $recordNumber ]
                 [ No dialog ]
                 End If
                 If [ not IsEmpty(line items button::xButton_ID) ]
                 Go to Related Record [ From table: “line items button”; Using layout: “LINE ITEMS button” (line items button) ]
                 [ Show only related records ]
                 Go to Record/Request/Page
                 [ First ]
                 Loop
                 Duplicate Record/Request
                 Set Field [ line items button::xtechsheetFK; $TECHSHEETID ]
                 Omit Record
                 Go to Record/Request/Page
                 [ First ]
                 Omit Record
                 Exit Loop If [ Get ( FoundCount )=0 ]

                 Go to Layout [ original layout ]
                 Go to Record/Request/Page [ $recordNumber ]
                 [ No dialog ]
                 End If
                 If [ not IsEmpty(line items other::xother_ID) ]
                 Go to Related Record [ From table: “line items other”; Using layout: “LINE ITEMS other” (line items other) ]
                 [ Show only related records ]
                 Go to Record/Request/Page
                 [ First ]
                 Loop
                 Duplicate Record/Request
                 Set Field [ line items other::xtechsheetFK; $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 [ $NewRecordNumber ]
                 [ No dialog ]
                 End If

                  

                 Do I need to put Go to Record/Request/Page [ $NewRecordNumber ] more places..?

                  

            • 3. Re: Dublicate record
              philmodjunk

                   You've put it exactly where I suggested putting it. I see no obvious reason why it isn't making the newly created parent record the current record.

              • 4. Re: Dublicate record
                philmodjunk

                     Just had an idea. Try adding a commit records just after the Duplicate Records step that duplicates the parent record, THEN use set variable to capture the current record number of the newly duplicated record.

                • 5. Re: Dublicate record
                  hanstrager

                       It still dosen't go anywhere. I have put the $NewRecordNumber at the last record/request/page as you said. Is it me who gets it all wrong?.

                       now I have this:

                       Freeze Window
                       Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                       Duplicate Record/Request
                  #The 'set variable' for go to dublicated record
                       Commit Records/Requests
                       Set Variable [ $NewRecordNumber; Value:Get(RecordNumber) ]

                       Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                       Go to Record/Request/Page [ $RecordNumber ] [ No dialog ]
                       If [ not IsEmpty(Line Items Fabric::TechSheetID_FK) ]
                       Go to Related Record [ From table: “Line Items Fabric”; Using layout: “LINE ITEMS Fabrics” (Line Items Fabric) ] [ Show only related records ]
                       Go to Record/Request/Page [ First ]
                       Loop
                       Duplicate Record/Request
                       Set Field [ Line Items Fabric::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 [ $recordNumber ] [ No dialog ]
                       End If
                       If [ not IsEmpty(line items zip::xZip_ID) ]
                       Go to Related Record [ From table: “line items zip”; Using layout: “LINE ITEMS zip” (line items zip) ] [ Show only related records ]
                       Go to Record/Request/Page [ First ]
                       Loop
                       Duplicate Record/Request
                       Set Field [ line items zip::xtechsheetFK; $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 [ $recordNumber ] [ No dialog ]
                       End If
                       If [ not IsEmpty(line items button::xButton_ID) ]
                       Go to Related Record [ From table: “line items button”; Using layout: “LINE ITEMS button” (line items button) ] [ Show only related records ]
                       Go to Record/Request/Page [ First ]
                       Loop
                       Duplicate Record/Request
                       Set Field [ line items button::xtechsheetFK; $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 [ $recordNumber ] [ No dialog ]
                       End If
                       If [ not IsEmpty(line items other::xother_ID) ]
                       Go to Related Record [ From table: “line items other”; Using layout: “LINE ITEMS other” (line items other) ] [ Show only related records ]
                       Go to Record/Request/Page [ First ]
                       Loop
                       Duplicate Record/Request
                       Set Field [ line items other::xtechsheetFK; $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 [ $NewRecordNumber ] [ No dialog ]

                       End If

                        

                       I also tried to put the $NewRecordNumber into all the record/request/page it then goes to the last record, but then the line items dosen't copy.

                  • 6. Re: Dublicate record
                    philmodjunk
                         

                              I also tried to put the $NewRecordNumber into all the record/request/page it then goes to the last record, but then the line items dosen't copy.

                         That does not make sense to me. What record you go to at the very end of your script will have no effect whatsoever on whether or not your script duplicates records in the line items table.

                    • 7. Re: Dublicate record
                      philmodjunk

                           I can't help wondering if all of these layout changes back and forth might trip another script trigger and run a script that interferes with your duplicate records script.

                           If you have FileMaker Advanced, I suggest running this script in the debugger and watching to see what record is the current record on your layout at all times.

                           If you do not have Advanced, I'd put a show All records step just after Duplicate Record to see where that record ends up when it is first duplicated and then do a show all records to pause the script just before your script does the go to Record/request/page [$NewRecordNumber] step to see what layout and found set is in place at the time this last script step is executed.

                      • 8. Re: Dublicate record
                        hanstrager

                             very bizarre - ran the script bugger a few times without doing any changes to my script, and now it seems to work. Just to clarify, is this how the script should look like?

                             Freeze Window
                             Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                             Duplicate Record/Request
                             #The 'set variable' for go to dublicated record
                             Commit Records/Requests
                             Set Variable [ $NewRecordNumber; Value:Get(RecordNumber) ]
                             Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                             Go to Record/Request/Page [ $RecordNumber ] [ No dialog ]
                             If [ not IsEmpty(Line Items Fabric::TechSheetID_FK) ]
                             Go to Related Record [ From table: “Line Items Fabric”; Using layout: “LINE ITEMS Fabrics” (Line Items Fabric) ] [ Show only related records ]
                             Go to Record/Request/Page [ First ]
                             Loop
                             Duplicate Record/Request
                             Set Field [ Line Items Fabric::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 [ $recordNumber ] [ No dialog ]
                             End If
                             If [ not IsEmpty(line items zip::xZip_ID) ]
                             Go to Related Record [ From table: “line items zip”; Using layout: “LINE ITEMS zip” (line items zip) ] [ Show only related records ]
                             Go to Record/Request/Page [ First ]
                             Loop
                             Duplicate Record/Request
                             Set Field [ line items zip::xtechsheetFK; $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 [ $recordNumber ] [ No dialog ]
                             End If
                             If [ not IsEmpty(line items button::xButton_ID) ]
                             Go to Related Record [ From table: “line items button”; Using layout: “LINE ITEMS button” (line items button) ] [ Show only related records ]
                             Go to Record/Request/Page [ First ]
                             Loop
                             Duplicate Record/Request
                             Set Field [ line items button::xtechsheetFK; $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 [ $recordNumber ] [ No dialog ]
                             End If
                             If [ not IsEmpty(line items other::xother_ID) ]
                             Go to Related Record [ From table: “line items other”; Using layout: “LINE ITEMS other” (line items other) ] [ Show only related records ]
                             Go to Record/Request/Page [ First ]
                             Loop
                             Duplicate Record/Request
                             Set Field [ line items other::xtechsheetFK; $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 [ $NewRecordNumber ] [ No dialog ]
                             End If

                             Also do you know if it's possible to also copy the status of my radio buttons, even though they have an auto enter fill..?

                        • 9. Re: Dublicate record
                          philmodjunk

                               The auto-enter will take place when the record is duplicated if your auto-enter options on that field permit replacing an existing value. You can always use set field after the record has been duplicated to set the radio button field to a specified value if that is needed. (And you can set a variable to a radio button field value, duplicate the record and then set field on the new record to set the radio button field value back to that of the original record if that is necessary--though I doubt that it is.)

                          • 10. Re: Dublicate record
                            hanstrager

                                 Not entirely sure how to do this. I have to make a new variable: Set Variable [ $radiobutton; Value:productionswitch ]

                                 i place this here

                                 Freeze Window
                                 Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                                 Duplicate Record/Request

                                 [ $radiobutton; Value:productionswitch ]


                                 #The 'set variable' for go to dublicated record
                                 Commit Records/Requests
                                 Set Variable [ $NewRecordNumber; Value:Get(RecordNumber) ]
                                 Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                                 Go to Record/Request/Page [ $RecordNumber ] [ No dialog ]

                                 ...

                                 but not sure what to do next?

                            • 11. Re: Dublicate record
                              philmodjunk

                                   Does this mean that auto-enter is changing the value in the duplicated record such that it is different from the original and you want them to be the same?

                                   I want to be sure on that before I suggest an answer.

                              • 12. Re: Dublicate record
                                hanstrager

                                     it's basically a radio button set, which I use as a switch that hides certain fields and controls which print layout to go to. That's why it has an auto enter so when i make a new record it is always set to a default. but when I duplicate the record i want the radio button switch to be set to the same value as the record I'm duplicating from.

                                • 13. Re: Dublicate record
                                  philmodjunk

                                       But why does the auto-enter calculation produce a different value when the record is duplicated?

                                       Under most circumstances that I can imagine, such a field would still have the same value as that in the original record and then there is no need for this.

                                       but if you truly need it, then:

                                       Freeze Window
                                       Set Variable [ $RecordNumber; Value:Get ( RecordNumber ) ]
                                       Set Variable [ $radiobutton; Value:TECHNICAL SHEET 2::productionswitch ]
                                       Duplicate Record/Request
                                       Set Field [ TECHNICAL SHEET 2::productionswitch ; $radiobutton ]
                                       #The 'set variable' for go to dublicated record
                                       Commit Records/Requests
                                       Set Variable [ $NewRecordNumber; Value:Get(RecordNumber) ]
                                       Set Variable [ $TECHSHEETID; Value:TECHNICAL SHEET 2::xTechnical sheet_ID ]
                                       Go to Record/Request/Page [ $RecordNumber ] [ No dialog ]

                                  • 14. Re: Dublicate record
                                    hanstrager

                                         Not sure, but your script works perfectly. See a screen shot of my out enter set up, maybe I'm doing something fundamental wrong..?