1 2 Previous Next 19 Replies Latest reply on Jul 22, 2016 1:58 PM by David Moyer

    Perform Script by Name

    lmarcinelli

      I would like to call a script based on a variable passed, i.e..., Perform Script [ $id&"invoice']

      I am attaching a file, in case I am not clear.

       

      thanks in advance!!!

      Lisa

        • 1. Re: Perform Script by Name
          ninja

          Perform the Script "Script Rerouter"

           

          Which you write as:

           

          If ($id&'invoice' = "red")

              Perform Script [RedScript]

          EndIf

          If ($id&'invoice' = "blue")

              Perform Script [BlueScript]

          EndIf

          ........

          • 2. Re: Perform Script by Name
            SteveMartino

            Still not clear.  I'm sure as this is just a mock up that you don't intend to use a name as the primary key ID.

            But basically, I don't see the need to create a variable of the id as a script parameter, then call a script.  You may be able to do it all at once.

            Will every different company require different search parameters?

            2 initial ways, based on the little info you provided:

            1.  Use the script parameter and hard code with a bunch of "Else If" statements.  Probably not the best because this may require constant maintenance.

            For example:

            If [Get(scriptparameter) = "USF"]

                Perform Script ['Search USF']

            Else if [Get(ScriptParameter= "GIN"]

                Perform Script ['Search GIN']

            etc....

             

            or

            2.

            Enter Find Mode

            If [Get(scriptparameter)= "USF"]

                //enter search parameters with set field steps or multiple search parameter for 'or' or 'and' finds

            Else if [  //next id  ]

                //enter search parameters with set field steps or multiple search parameter for 'or' or 'and' finds

            etc..

            Perform Find [ ]

             

            Neither are ideal.  More info would help.

            • 3. Re: Perform Script by Name
              lmarcinelli

              Hi Eric,

              Yes, that is what I have but I need the nested ifs for over 100 conditions. I would love a case statement here!

              thanks for responding so quickly.

              Lisa

              • 4. Re: Perform Script by Name
                lmarcinelli

                Hi Steve,

                Yes, each condition will require it's own unique set of finds. I originally did it your second example, then switched to your first example to make it easier for future programmers... I was hoping to simplify it even more. I HATE nested Ifs 

                 

                thanks for your speedy reply.

                Lisa

                • 5. Re: Perform Script by Name
                  beverly

                  I wonder if the FMP protocol would help here?

                  you can call a db AND script

                   

                  beverly

                  • 6. Re: Perform Script by Name
                    beverly

                    p.s. update link (includes FM15):

                    Opening shared databases remotely using a URL | FileMaker

                    beverly

                    • 7. Re: Perform Script by Name
                      wimdecorte

                      Yep, in addition to that AppleScript can do it too and so can ActiveX on Windows.  Problem is that you'll be  hard-coding script names so they will no longer be name-change safe and won't show up as referenced in any of the analysis tools.

                      1 of 1 people found this helpful
                      • 8. Re: Perform Script by Name
                        David Moyer

                        I agree that you should resort to the FMP protocol.

                        It is true that you will need to manage (or prevent) script name changes, by definition.

                         

                        But, if you've got a hundred scripts, check out the FM Help article:  Opening files using a URL

                         

                        example:

                        "fmp://192.168.10.0/Clients.fmp12?script=ListClients&param=TopClients&$NumberToList=10"

                        • 9. Re: Perform Script by Name
                          ch0c0halic

                          I create a sub-script to do this. Use Set variable to define the URL needed to perform the script. Then use Open URL to perform the script.

                           

                          Pass in the script name and any parameters used in the script.

                          Then separate the parameters into variables:

                          $script_name

                          $script_param

                           

                           

                          "fmp://" & Get ( HostName ) & "/" & Get ( FileName ) & "?script=" & $script_name & "&param=" & $script_param

                           

                          The use:

                          Open URL ["$url"]

                           

                           

                          The HostName and File name are self referential so the script is called in the current file. Change them as required if the script is not local.

                          The "fmp://" defines the application to direct the URL to is FMP.

                          • 10. Re: Perform Script by Name
                            David Moyer

                            Continuing my thoughts ...

                            ... on the other hand, consider this a (pita) compromise:

                            I  think all of us would abhor doing the following ... but I think it solves the problem of being able to use calculated script names to call scripts - you can do it with this.

                            Plus, when the actual script name does change, it won't break your code.

                             

                            In this example, It's important to note that when you call the ScriptChooser script, from say Script A, the script you choose will be executed and the program flow will return to Script A where it left off. (as it should).

                             

                            Capture.PNG

                            • 11. Re: Perform Script by Name
                              ninja

                              Consider whether you can skin it a different way...

                               

                              Do your 100 different "scripts" come from combinations of only 8 subtasks?

                               

                              If ( $script = red or $script = green or $script = yellow)

                                   Perform Script [subtask1]

                              EndIf

                              If ( $script = red or $script = black or $script = purple)

                                   Perform Script [subtask2]

                              EndIf

                              ........ {8 times instead of 100}

                               

                              You could do the same with passing a list of script parameters

                              ...or maybe even coding into a field on the customer table what subscripts to run...

                              • 12. Re: Perform Script by Name
                                ninja

                                No cases in scripts...just the ifs....but after all, that's just syntax anyway.

                                That cool little "duplicate" button helps a fair bit...

                                • 13. Re: Perform Script by Name
                                  jormond

                                  I used to dislike nested ifs. However, in practice, when I've had to go back and change scripts or debug them... I found indirection to be more like misdirection. It can become tricky to debug something that requires you to know the context of multiple ( and sometimes many ) different variables.

                                   

                                  Last year, especially, I really started using more defined structure and explicit setting of variables and forking of scripts. It was a touch longer to write, but paid dividends when I have to go back to rework something. Most times I can read through a script and debug it without running it in the debugger. Then fix and test using the data viewer and debugger.

                                   

                                  Fixing things became significantly faster. Writing new scripts was more efficient, even though scripts were a touch longer. The performance difference was only nominal at the worst. In 99% of the scripts...there was no performance impact.

                                   

                                  Just because of changing business logic, rules, etc...I see it as you write a script 1x. And you will change it 10x. Or debug it 100x. Trying to identify the oddball scenario that lead to the perceived bug.  Just my thoughts.

                                   

                                  lmarcinelli wrote:

                                   

                                  Hi Steve,

                                  Yes, each condition will require it's own unique set of finds. I originally did it your second example, then switched to your first example to make it easier for future programmers... I was hoping to simplify it even more. I HATE nested Ifs

                                   

                                  thanks for your speedy reply.

                                  Lisa

                                  • 14. Re: Perform Script by Name
                                    brsamuel

                                    The free BaseElements plugin includes a function for executing scripts by a calculation, but you would still have the issue of renamed & unreferenced scripts causing potential issues.

                                    1 2 Previous Next