6 Replies Latest reply on Jan 2, 2013 2:08 PM by NetDude

    Script request

    NetDude

      Title

      Script request

      Post

           Folks Im looking at creating a simple script that will do the following:

           When a user presses the New Record button  The new record ID is also populated into a seperate table.

           I started to create a script that looks like this:
           Go to Layout ["PrimaryLayout" (Primary)]
           New Record/Request
           Set Variable [$PrimaryID; Value:Primary::PID]
           Go to Layout ["SecondaryLayout" (Secondary)]
           New Record/Request
           Set Field [Secondary::PrimaryID; $PrimaryID]

           This script technically works when I place a button on the page and set it to run the script. 

           1) I need this scripts to run when the native FM New Record button is pressed.

           2) The script indicates that it needs to Go to Layout "SecondaryLayout" however I do NOT want to go to the page I simply want the record to be added and the focus remains on "PrimaryLayout"

           Any help would help, THANK YOU!!!!

        • 1. Re: Script request
          philmodjunk

               If you have FileMaker Advanced, you can do this by installing a custom menu that performs your script in place of the New Record menu option. (This also affects the new record button in the tool bar and the new record keyboard shortcut.)

               If you do not have advanced, the best that you can do is hide and lock the status area so that users have to click your button to create a new record. There are ways with field validation or manage | Security that can at least prevent users from using the keyboard shortcut or New record from the records menu if you have to take this route.

          • 2. Re: Script request
            schamblee

                 The answer to part 2 or your question.  You need to add Freeze Window to your script.  It will still go to the second layout, but the user will only see the current layout.

            http://www.filemaker.com/11help/html/scripts_ref2.37.8.html

            • 3. Re: Script request
              NetDude

                   Thank you folks for your help. I did notice that by simply taking out Go to Layout ["SecondaryLayout" (Secondary)] I was able to not actually leave the current layout and still have the script insert the record. HOWEVER what I am noticing is that upon running the script (Associated a button to activate the script) that two records get created and the ID from the 2nd record is the one that is getting populated intot he Secondary table.

              Here is the script:

              Go to Layout ["PrimaryLayout" (Primary)]
              New Record/Request
              Set Variable [$PrimaryID; Value:Primary::PID]
              New Record/Request
              Set Field [Secondary::PrimaryID; $PrimaryID]

              • 4. Re: Script request
                philmodjunk

                     As S. Chamblee recommended, you need a Freeze Window step:

                Go to Layout ["PrimaryLayout" (Primary)]
                New Record/Request
                Set Variable [$PrimaryID; Value:Primary::PID]
                Freeze Window
                     Go to Layout ['Secondary layout" (Secondary) ]
                     New Record/Request

                Set Field [Secondary::PrimaryID; $PrimaryID]
                     Go To Layout [Original Layout]

                     Note, however, that scripts that change layouts can trip script triggers such as OnLayoutEnter, OnLayoutExit, OnRecordLoad, OnObjectEnter, OnObjectExit and OnRecordCommit. If such triggers are in place on either layout, you may need to take steps to keep them from performing scripts during the execution of your New Record script. One way to do that is to add a layout for your script with no script triggers, but based on the correct table. Another method is to set a global variable with a value at the start of the above script and then to set it back to null or False at the end, then your trigger controlled scripts can check the value of this global variable and exit without doing anything if a the global variable has been set.

                • 5. Re: Script request
                  schamblee

                       Your script creates two records in the current Primary Layout.  You should be on your Primary Layout with the "New Record" button, if so your script would be as follows:

                       New Record/Request
                       Set Variable [$PrimaryID;Value;Primary::PID]
                       Freeze Window
                       Go to Layout "[SecondaryLayout"(Secondary)]
                       New Record/Request
                       Set Field[Secondary::PrimaryID;$PrimaryID]
                       Go to Layout"[PrimaryLayout"(Primary)]

                        

                        

                        

                  • 6. Re: Script request
                    NetDude

                         S Chamblee and Phil , Thank you this works great