13 Replies Latest reply on May 3, 2014 10:09 PM by sporobolus

    Variable script name call?

    chronister

      Hello all,

       

      I hope all are doing well this eve.

       

      I am trying to set a script name in a field, and then call it in another script via the variable that gets set. Is there a decent way to do this?

       

      Basically I have assignTo - Bob

       

      I can get the part I want (assignTo), but am having trouble determining how to use that variable as a script name.

       

      Hope someone can help point me in the right direction

        • 1. Re: Variable script name call?
          keywords

          There is a Get ( ScriptName ) function. Have you tried using it?

          • 2. Re: Variable script name call?
            chronister

            Thanks for the quick response, but that is not what I am after....

             

            Essentially I am trying to have something like this inside another script....

             

            $scriptName = calculationToFindName(stringToLookIn)

             

            PerformScript[$scriptName]

            • 3. Re: Variable script name call?
              steve_ssh

              Hi Nate,

               

               

              Regarding Dynamic Script Choice:

               

              If you are looking to invoke a script where said script is determined dynamically at runtime based on the contents of a field or a variable, then AFAIK, there are a few options available to you.  None of these are probably as direct/compact as you might be hoping for:

               

              1) Utilize a plugin that allows you to invoke a Script by name.   Both BaseElements and ScriptMaster allow for this (probably others, too).

               

              2) Utilize Insert From URL (or a WebViewer) to trigger a script on FileMaker Server, via one of the CWP API's (e.g. the PHP API).  [Requires use of FMS]

               

              3) Utilize a WebViewer to invoke a FMP URL which invokes a script in the locally running file.  [Requires that the file be hosted or running on FMGo]

               

                  Edit:  Looks like item #3 can be also done with a non-hosted FM v.13.0v2 file.

               

              4) Write a script that has all required conditional logic to be able to branch accordingly based on input or context and, in turn, trigger the desired script. [Requires knowing and coding all possibilities in advance]

               

              5) If on OSX, you might be able to utilize AppleScript (from within a FileMaker script) to invoke a FileMaker script by name.  I think I tried this a long time ago, and can not remember if it worked super-well or not.  I have a vague recollection that I did come up against some sort of small wrinkle with this idea.

               

              Each of the above comes with its own set of pluses and minuses.

               

               

              Of Note:

               

              In scenarios where you are writing code that will invoke scripts dynamically by name, unless you have gone to some careful measures to make your code tolerant of script renaming, you run the risk of having things break if you rename a script.

               

              Item #4 above does not run this risk of breaking with a script rename, since it does not rely on the script names.  As such, I see it as the most safe of all of the above options, though, understandably, not the option that I would relish if the business logic is extensive or complex.

               

               

              Beyond the Above:

               

              One question that is oftentimes raised in response to questions such as this post is:

               

                 What is the goal behind this particular functional need?

               

              It may be that, with a little bit of background to the situation, someone on TechNet might propose a suggestion that elegantly meets the need without requiring the dynamic script determination.  I certainly understand and appreciate how cool it would be to be able to dynamically determine the script to run in FM, but it might still be worth posting a little background to see if a good suggestion comes forth.

               

              Hope this helps & sincere regards,

               

              -steve

               

               

               

              Message was edited by: steve_ssh

               

                     Added note in item #3 regarding FM 13.0v2

              2 of 2 people found this helpful
              • 4. Re: Variable script name call?
                wimdecorte

                6) on Windows you can use the FM ActiveX interface to call a script from VBscript, PowerShell,...

                • 5. Re: Variable script name call?
                  keywords

                  Another approach might be to call a script which itself branches to initiate other scripts depending on circumstances.

                  • 6. Re: Variable script name call?
                    chronister

                    Ok.. here is the background on exactly what I want to do..... and why I am doing it.

                     

                    The application I am developing is to track projects across the many parts from start to finish (we are a custom graphics design and printing firm). I have a list of workorder types (Screen printing, Vinyl, Paper, Embroidery etc) that are tied to our projects. Based on the type, there are a list of items associated with them that are the steps needed for that project to be completed. We have offsite but in-house production, offsite vendors, in-house production and design so keeping track of multiple projects and what phase it is in has been a challenge. I have a task list that allows us to check things off. (see screenshot)

                     

                    screenCap.jpg

                    I am wanting to set triggers on these checkboxes to perform other tasks (e.g. assign to another person, set status options, remove project items from inventory ). I am trying to make it dynamic in that I set a field called Script Param to a value like this  assignTo - Nathan

                     

                     

                    I am wanting to write one script that I can call and "pass" the parameter I want after the hyphen. I can break the string down and get the parts I want, so all I am left wit is trying to actually run the script that I have set to run.  I am thinking number 4 is going to be the way to accomplish this in the cleanest manner.

                    • 7. Re: Variable script name call?
                      jbante

                      If you're up-to-date with the latest version of FileMaker, you can also use the fmp URL scheme with the Open URL script step.

                      • 8. Re: Variable script name call?
                        Stephen Huston

                        You indicated that you understand how to pass script parameters, capture their content and parse separate values to $variables.

                         

                        I often then run a string of If/Else If tests to pick the next action, something such as:

                        --

                        If [$action = "reassign"]

                             Perform Script [Reassign; with whatever paramter it may need]

                        Else If [$action = close"]

                             Perform Script [Close; with whatever paramter it may need]

                        Else If (etc. as often as you need it)...

                             etc.

                        End If

                        --

                        This lets you call this central script from wherever you need it, passing the correct multi-piece parameter to it, and let it sort out which script gets executed from the triggered script.

                        • 9. Re: Variable script name call?
                          chronister

                          I thought about that ... but was not sure about what URL to use so that it is available on all systems and whether a username and pass had to be hard coded to the URL.

                           

                          I think I am getting it with the master script that determines what to run based on what it passed to it.... I have the assignTo - XXX part working. It is assigning to the correct person based on who tell it.

                           

                          Thanks folks     

                          • 10. Re: Variable script name call?
                            PeterWindle

                            There is another way of acheiving this, but it's not elegant.

                             

                            I have done this using a layout with buttons that perform scripts. The Buttons each have unique object name as well as a script trigger to perform the same script as what the button is actually defined to do.... bare with me... then, in the script, there is a "goto object" - which you can set using a variable/field value. So when the goto object script performs, it selects the button, which in turn activates the script that the button normally performs when you click on it and viola, it works the same way as clicking on the actual button. I find this useful when the button appear on the layout anyway, but if it does not, you can create a layout dedicated to button objects with script triggers on them.

                             

                            Like I said, not elegant, but it works.

                            • 11. Re: Variable script name call?
                              steve_ssh

                              Thanks for mentioning this, Jeremy.  I have not stayed up-to-date with the latest v.13 and didn't know about this until you mentioned it.

                               

                              Best,

                               

                              -steve

                              • 12. Re: Variable script name call?
                                user19752

                                Latest FMP13 not need username/password since the script will run in the file already opened.

                                "fmp://$/" & Get ( Filename ) & "?script=" & $ScriptName

                                • 13. Re: Variable script name call?
                                  sporobolus

                                  on 2014-05-02 17:01 steve_ssh wrote

                                  4) Write a script that has all required conditional logic to be able to branch accordingly based on input or context and, in turn, trigger the desired script.

                                   

                                  i have done this by passing a parameter in lieu of the script name and using an

                                  if/then chain to test the parameter and branch to the appropriate script; with

                                  a little care it is not too hard to maintain, and performs very well

                                   

                                  5) If on OSX, you might be able to utilize AppleScript to invoke a FileMaker script by name.  I think I tried this a long time ago, and can not remember if it worked super-well or not.  I have a vague recollection that I did come up against some sort of small wrinkle with this idea.

                                   

                                  i have done this, a few years ago, and found that it was quite slow; the kind

                                  of system where dynamic calls are useful often does a lot of such calls, at

                                  least mine did, and it was the difference between a few hours and a few days of

                                  processing time on a data driven system