10 Replies Latest reply on Oct 3, 2011 8:56 AM by akliewer99

    Need best way to Perform Script [Script name by calculation]

    akliewer99

      Title

      Need best way to Perform Script [Script name by calculation]

      Post

      I have 72 possilbe script names that could run in a certain situation.

      How can I use the "Perform Script" step when I don't know the exact script name yet? I need the ability to "Script Name by Calculation" like the "Go to Layout" has.

      What is the current work around?

      Any ideas are GREATLY appreciated!

      Arlene Smile

        • 1. Re: Need best way to Perform Script [Script name by calculation]
          philmodjunk

          What is different for each of your "72 possible scripts"? Perhaps you can use one script but pass a script parameter to it so that one script can function in place of all or some of these scripts.

          Your only option for using a calculation to select which script to run is another script with a chain of  If-Else If steps to control which script get's performed.

          • 2. Re: Need best way to Perform Script [Script name by calculation]
            akliewer99

            Everything. Each script is completely different. Each with different layouts and variables. Some open new windows and others do not.  Besides that these script names could change at a moments notice. It would be enormous for one script and tons of if - thens to control this.

            Isn't there someway to "Evaluate ("Perform Script" & $var_script_name)

            Just wishing!

            • 3. Re: Need best way to Perform Script [Script name by calculation]
              philmodjunk

              Feel free to explain what you are doing here. This sounds a bit unusual and maybe there is an alternate approach you can use that will be much easier to work with.

              these script names could change at a moments notice

              Sounds especially odd as frequent changes to script names is very unusual for a Filemaker database and changing a script name won't necessarily break the script that I am describing that would use a chain of If-Else If's to determine which script to perform.

              • 4. Re: Need best way to Perform Script [Script name by calculation]
                akliewer99

                Okay they say a picture is worth a thousand words so this is my screen. I have created a dynamic interface. All the buttons are table driven. My Hubby saids I have over done it. But I like the fact that all my layouts automatically update on a whim.

                However some of my Layouts are pop-up windows and I want to use a script to open them. Hence my problem. Take a look at the screen shot.

                Thanks for taking some of your time to help me!

                • 5. Re: Need best way to Perform Script [Script name by calculation]
                  philmodjunk

                  But why do you want to rename scripts on the fly?

                  Selecting different scripts on the fly is quite possible here and the script name displayed in the portal need not be the actual name created in the scriptmanager and the If-Else IF chain of script steps can do the script selecting here.

                  Most of this looks like things that generalized scripts could handle if you passed the right field, table occurrence, layout and window name data to it.

                  • 6. Re: Need best way to Perform Script [Script name by calculation]
                    akliewer99

                    I am stewing on your suggestion. Not really sure how efficient coping and pastinge 72 "else if" statements would be. It would be some ugly code. Not to mention the time investment.  It would take a while manually to key in all those possibilities.  I just thought there would be a better way. Thanks anyways.

                    • 7. Re: Need best way to Perform Script [Script name by calculation]
                      bumper

                      Have you tried passing named pair parameters? There are a number of custom functions that allow you to set variables from field data or "hard coded" to the button and then insert them into a master script. 

                      • 8. Re: Need best way to Perform Script [Script name by calculation]
                        akliewer99

                        I am open to ideas. What do you mean by passing named pair parameters to a master script? Can you give me an example?

                        • 9. Re: Need best way to Perform Script [Script name by calculation]
                          bumper

                          FileMaker buttons can pass a script parameter to the ensuing script. Developers being the greedy lot that they are were not satisfied with just one and set about to find a way to push several parameters at once. The result is that now there are many useful ways to accomplish this task. The name-value pair is usually considered to easier to read because you declare a name variable and then the value that you wish to push. Put a group of these together and you usually in conjunction with a custom function that puts the named variable in to FileMaker's memory where it can be used while the script is running.

                          The one that I use the most is for new related record creation. It is quite simple compared to many available today. In the script parameter calculation box I list the variable names, say $Layout, and the name of the layout for the table in which the record is to be created. A lot of other data can be added, obviously the primary key of the parent record, any other field data, etc. This is wrapped in a List function, which the cf takes and does its magic, then the script uses the variables as if they were declared with in the script itself. The nice part is that I can paste a copy of that button throughout the file and it will create a child record with no changes, or I can alter the pairs as needed, say for a different table combo, and still use the same master script. 

                          If you google "name pair values filemaker" you will get a number of hits that will give you a more in-depth analysis of this process. There are a few CFs for this available for free on BrianDunning.com. And in retrospect I am not even sure you can pass a script name via a variable, not saying it can't be done, I've just never needed to do it.  So PhilModJunk may be right on two counts, do you really just have to do it this way, ie 72 scripts, and if the answer is yes you may just have to say hello to mr "if else" Perhaps you can reduce the number of scripts, I use the afore mentioned technique to open and close a number of pop-up windows for data entry, they all run on the same master script, then if you need to run another script to assemble data, etc, use script triggers, on layout load, etc, to run those scripts.

                          • 10. Re: Need best way to Perform Script [Script name by calculation]
                            akliewer99

                            Thanks Bumper. That was GREATLY appreciated. The "name pair values" suggestion have given me lots of food for thought. I'm pretty sure I can come up with something.

                            Due to PhilModJunk answer, I have started to rework all my scripts. This new idea will fit in real good!

                            Thanks to both of you, PhilMondJunk and Bumper! This is why I love this forum.

                            As I get more experience, I hope to help out others someday just like you guys did for me!