1 2 Previous Next 22 Replies Latest reply on Mar 9, 2017 4:09 AM by roryduffy

    Name a global variable in a script.

    roryduffy

      Hi,

       

      I hope you're all well.

       

      I'd like to create a 'back button' in Filemaker, similar to a browser navigation back button, using the commonly tried-and-tested Global Variable technique.

       

      So far, I have got this to work for 1-step back, by setting the following script trigger on layout exit, which is great:

       

      1.

      Set Variable

      ( $$Backward )

      Value; ( Get ( LayoutName ) )

       

      2.

      Go to Layout Name by calculation: ( $$Backward )

       

      However, I'd like to make this work for multiple steps. I'm aware that as you navigate through the layouts, a script trigger needs to 'log' the browser history. To do this, I tried setting up a sequence of 10 nested IF statements in my script:

       

      If

      ( not ( IsEmpty ( $$Layout01 ) ) )

           If

           ( not ( IsEmpty ( $$Layout02 ) ) )

                If

                ( not ( IsEmpty ( $$Layout03 ) ) )

       

      and so on..., and then doing the same in the "Go to Layout" script to determine which Global Variable should be used. Unfortunately, while this worked, with each subsequent level down, Filemaker's speed plummeted to a crawl until I got a spinning beach ball of death.

       

      Is there a way in which a Global Variable can be generated automatically/incrementally? I've read online that it can be done, as a "Dynamic Global Variable". Although I've found out how this can be implemented in a field, I can't find anywhere that explains how this can be implemented in a script.

       

      Essentially, I'm looking to create 2 scripts:

      1. A script trigger activated on Layout Exit, which generates Dynamic Global Variables to 'log' browser history.

      2. A go to script that analyses what number Global Variable you're currently on, and then subtract 1 to go to the layout previously logged to that.

       

      I believe "Dynamic Global Variables" might be the key to all of this, but I'm also wondering whether the script trigger should be activated on Layout Entry rather than Layout Exit.

       

      Thanks,

       

      Rory

        • 1. Re: Name a global variable in a script.
          siplus

          Why don't you simply append the layout name you land on to a $$Variable ? When you hit back/forward you inc/dec a $$index which corresponds to a specific item in the $$Variable.

           

          (You can create variables using Evaluate.)

          • 2. Re: Name a global variable in a script.
            roryduffy

            Hi Si,

             

            Thanks very much. Please can you explain to me how to do that in a script?

             

            In Script Workspace (FMP14), I tried searching for "Evaluate" (and also "Let") functions in the Steps pane on the right-hand side but they're not coming up.

             

            Also, the previous layout as a Global Variable would replace the layout before that, so I'd end up in a loop where I'm simply jumping between 2 layouts; the next layout becomes my previous layout and vice versa etc.

             

            I'm probably misunderstanding what you mean exactly but if you could explain in more detail would be much appreciated.

             

            Thanks,

            Rory

            • 3. Re: Name a global variable in a script.
              beverly

              You are confusing scripts and functions. You can get information on any script step OR function here:

               

               

              If EN is not your language, you can change the country code. There is also a direct link to help from FMP.

               

               

              Sent from miPhone

              • 4. Re: Name a global variable in a script.
                roryduffy

                Ah yes, of course I am - thanks. I definitely want to talk about scripts here (not fields - which is why I was not satisfied with the answers online which were all talking about fields).

                 

                First and foremost: I'm looking to create a script that can nominate an incremented/serialised Global Variable name. Is there a specific script step I can use for this purpose? The link you sent only lists them alphabetically.

                 

                e.g.,

                Set Variable ( ( $$[highestGlobalVariableNumber] ) + ( 1 ) )

                Value; ( Get ( LayoutName ) )

                 

                So I'm actually using a scripted formula to create the Global Variable, and then linking that Global Variable to the name of the current layout.

                 

                Thanks,

                Rory

                • 5. Re: Name a global variable in a script.
                  siplus

                  To start with I'd take a look at

                   

                  http://www.modularfilemaker.org/module/browser-navigation/

                   

                  to create a var on the fly in a script, see

                   

                  Creating a dynamic script variable name

                   

                   

                  a quick fun can be obtained by using the Data Viewer, if you have Advanced.

                   

                  Switch to "Watch", chick on "+", paste this:

                   

                  Evaluate (

                  Let ( $$myVar[33] = 5;

                  1 ) )

                   

                  then hit "Evaluate now", hit "Cancel", select the "Current" tab and there it is:

                   

                  Screen Shot 2017-02-23 at 15.03.29.png

                  • 6. Re: Name a global variable in a script.
                    roryduffy

                    Hi,


                    Thanks so much for this, it's really useful. Yes, I viewed these links before but I didn't understand how to build these into a script, because Evaluate and Let aren't coming up in the script steps pane on the right of the Script Workspace. Forgive me if I'm missing something obvious.

                     

                    Also, I downloaded and checked the Modular Filemaker downloads, which are really good. However, I didn't understand how to copy a custom function from one Filemaker solution to another. I researched custom functions and it appears that these are only available in Filemaker Advanced. I only have Filemaker Pro 14. Does that mean I can't copy and paste a custom function from one solution into another?

                     

                    If you could walk me through the script creation process for Creating a dynamic script variable name (e.g., go to Manage Scripts, create a new Script etc.) then I'd be eternally grateful! I got stuck on step 1, as it appeared to be a script but included "Evaluate" (which I couldn't find).

                     

                    Thanks,

                    Rory

                    • 7. Re: Name a global variable in a script.
                      BruceRobertson

                      "If you could walk me through the script creation process for Creating a dynamic script variable name"

                       

                      You absolutely do NOT want to do that.

                      You need to learn about how to use a single variable, which holds return delimited values, and add or remove values from that list. That's what Siplus means by append but he doesn't explain it. His description of how to use the evaluate function is also not necessary.

                       

                      Though the files at Modular FileMaker demonstrate how to do this in a very comprehensive way with custom functions the basic idea is this.

                       

                      When leaving a layout, your script trigger needs to do this:

                      Let( $$back = list( get( layoutName); $$back)

                       

                      Now to actually GO back:

                      Set Variable [ $targetLayoutName; getValue( $$back; 1)]

                      Set Variable [ $$back; middleValues( $$back; 2; valueCount( $$back)]

                      Go to layout by Name [ $targetLayoutName ]

                       

                      Though you do NOT need this for your back-nav feature, it will be useful to learn about numbered variables, also called repeating variables; and square bracket notation.

                      Example:

                      Let( $n = get( recordNumber); ""]

                      Let ( $$firstname[$n] = Contacts::firstName; ""]

                       

                      Example result:

                       

                      $$firstName[13] contains "John"

                      • 8. Re: Name a global variable in a script.
                        roryduffy

                        Hi Bruce,

                         

                        Thanks

                         

                        I did this though:

                        1. Scripts --> Script Workspace (or shift-command-S)

                        2. Located my Set Variable script triggered on Layout Exit (in this case, I called it "SV_Backward" )

                        3. Script step 1. Set Variable

                        4. Gave it a Name "$Backward" (in this case used the single dollar before the name as you suggest)

                        5. Copied and pasted the below text into Value:

                         

                        Let( $$back = list( get( layoutName); $$back)

                         

                        But when I clicked OK, it said "There are too few parameters in this function."

                        ?

                        Thanks

                        Rory

                        • 9. Re: Name a global variable in a script.
                          siplus

                          I see 3 opening "(" and only 2 closing ")"

                          • 10. Re: Name a global variable in a script.
                            hjgunn@mmedia.is

                            How about just use a variable $$stack and then read the names of the layouts you "touch" into the variable and separate them with the "return" character?

                             

                            Then you can read from the "stack" when backtracking and each time you read a line from the stack you "delete" the line you just read.

                            • 11. Re: Name a global variable in a script.
                              roryduffy

                              Ah, well noticed Siplus... But usually Filemaker would give you the there are more "(" than ")" or more ")" than "(" message.

                               

                              I've never used the "Let" Function before so I don't know what's wrong with the formula Bruce sent me as a script trigger.

                               

                              Thanks in advance.

                              • 12. Re: Name a global variable in a script.
                                roryduffy

                                Thanks HJgunn.

                                I'm not sure how that works exactly. Can I try Bruce's method first and then come back to yours? As I need walking through the process step-by-step.
                                If Bruce could help me on:

                                 

                                When leaving a layout, your script trigger needs to do this:

                                Let( $$back = list( get( layoutName); $$back)

                                Thanks,

                                Rory

                                • 13. Re: Name a global variable in a script.
                                  hjgunn@mmedia.is

                                  No problem, it's just a thought anyway.  :-)

                                  • 14. Re: Name a global variable in a script.
                                    roryduffy

                                    Cheers, I may pick you up on that thought :-)

                                    1 2 Previous Next