10 Replies Latest reply on Oct 25, 2013 2:36 PM by CraigWollman

    Entering custom code for a script

    CraigWollman

      Title

      Entering custom code for a script

      Post

           I've searched the forums and Youtube and elsewhere online but I can't seem to find a simple tutorial on entering code to create a script.  There's a lot of information on how to create a script using the "move" button to move built in script commands but I have no idea where and how to enter custom code.  There is also a lot of custom code tips out there but they assume a knowledge of where to type in this code.

           With that, can anyone point me in the right direction?

        • 1. Re: Entering custom code for a script
          CraigWollman

               Ooops, sorry, I'm using Filemaker Pro 8.5 with Windows XP

          • 2. Re: Entering custom code for a script
            philmodjunk

                 To create a script, pull down the script menu and select "manage scripts" or "script manager" (whatever they called it in your version).

                 Then click "New" to open the script editor and start a new script.

                 The available script steps are listed on the left hand side. Double click it to add it to your script.

                 Many script steps require that you specify additional details. While a script step in your script is highlighted, controls for making those selections appear at the bottom of the script editor.

                 A large number of script steps correspond to menu options you can select manually. If you are new to scripting, you may want to figure out how to do what you want by hand, writing down each step on a piece of paper. Then start a new script and try selecting the matching steps from your list in the same order. For simple scripts that could be all or nearly all you need do.

            • 3. Re: Entering custom code for a script
              CraigWollman

                   Phil, I was familiar with that aspect (or should I say I figured it out) but there are many scripts posted online in code form.that utilize if/then/else statements and the use of variables.  I don't see any reference to that in the standard script steps offered.  So how is code manually entered.  The script dialog doesn't seem to allow for that.

              • 4. Re: Entering custom code for a script
                CraigWollman

                     Sorry, Phil, I now see the logical statements and the set variable statement.  I'm sure I'll be able to piece something together from that.

                     Thanks again for your help

                • 5. Re: Entering custom code for a script
                  philmodjunk

                       I think you are expecting to get a "text editor" type interface for creating a script--something that developers have asked for for many years, but this is not how the script editor has been set up. It's all "point and click" until you get to a specify button for adding the necessary calculation expressions. Then you finally get a text editor for creating such expressions.

                  • 6. Re: Entering custom code for a script
                    CraigWollman

                         This script, when assigned to my sort button, only sorts in one order.  So far this is what I have:

                         if [$gSortOrder="desc"]

                           Set Variable [#gSortOrder; Value:"asc"]

                           Sort Records [Restore]  // I don't know why it says restore here.  I chose "descending"

                         Else

                           Set Variable [$gSortOrder;Value:"desc"]

                           Sort Records [Restore] // I don't know why it says restore here.  I chose "ascending"

                         End If

                          

                         I also can't find where I can tell it to run without the dialog prompt.  My code seems to be correct.  Do I need to initialize gSortOrder somewhere?  I don't think I do.

                    • 7. Re: Entering custom code for a script
                      CraigWollman

                           Ok, so I added a second $ before the variable name and now it works.  Not sure what that rule is but I saw some code online where all variables had a double $ in front.

                           So the sort now works in both directions but I can't find out how to suppress the dialog.

                      • 8. Re: Entering custom code for a script
                        philmodjunk

                             You are missing a dollar sign. A variable with one $ is a script variable. It retains a value only as long as the script is executing. A variable with two $$ is a global variable. It will retain a value until the user closes the file. (And each user on a hosted database has their own separate set of global variables and values.) Since you are using a single variable, it disappears and its value is lost each time the script finishes execution.

                             And please note that accidentally misspelling a script won't prompt you with an error. FileMaker will assume that you have a different variable.

                             

                                  I also can't find where I can tell it to run without the dialog prompt.

                             When you click a script step listed as part of your script it highlights and the controls for specifying any options for it appear at the bottom of the script editor. If you click sort records, there's a check box for suppressing the dialog box that appears at the bottom of the script editor.

                        • 9. Re: Entering custom code for a script
                          CraigWollman

                               Thanks so much Phil for clearing up why I need the extra $.  It works great now.  I supressed the dialog.  I just have one more thing to figure out but I'm going to do that on my own.

                                

                               Thanks again.


                               Craig

                                

                          • 10. Re: Entering custom code for a script
                            CraigWollman

                                 Which I just figured out.  It wasn't resetting to the top of the list of fields but I figured that out.