12 Replies Latest reply on Mar 2, 2017 1:53 PM by ezeitgeist

    Temporary globals?

    ezeitgeist

      I have a globals table where I keep all my global fields. I recall someone telling me that I could temporarily create globals for a specific layout that I could define in the script for that layout/popover/button/etc.

       

      (1) Did I just make that up in my head?

      (2) If not, how do I do that? (And what are the advantages/disadvantages of that [possibly imaginary] technique]?)

       

      PS Also currently utilizing for a Web Direct project (so within the bounds of any Web Direct limitations).

        • 1. Re: Temporary globals?
          Jaymo

          Sounds like you are talking about variables. Use the Set Variable step and declare a variable beginning with a single dollar sign for a local variable:

           

          $MyVar

           

          Variables behave similarly to global fields in a lot of situations.

           

          You can also define a global variable that will go beyond the current script by adding a second dollar sign to the name:

           

          $$MyVar

          1 of 1 people found this helpful
          • 2. Re: Temporary globals?
            siplus

            Jaymo answered perfectly to your point 1).

             

            I just want to add something to point 2) - just a crumble, regarding "disadvantages":

             

            If you want to create on-the-fly relationships, where you have a global text field that can be filled with pk's and link you to related records, you HAVE to use a global field, variables won't cut it.

            1 of 1 people found this helpful
            • 3. Re: Temporary globals?
              ezeitgeist

              No, I know variable use. I am looking for a field. I have a "selector" field that I want users to be able to enter a search term and click a search button and then I match a searched record in a different table. I know I can just create a gSearch field in my globals table, but I was wondering if I could somehow create a global field and not have to have it parked in a table. Again, I could have just made this up in my head.

              • 4. Re: Temporary globals?
                philmodjunk

                You can even programmatically create variables with the Let and evaluate functions.

                 

                Set Variable [$Dummy ; Evaluate ( "Let [ $Var1 = 1 ; $Var2 = 2 ; $Var3 = 3 ] ; 1 )" ) ]

                 

                would create three variables named $Var1, $Var2 and $Var3 while assigning the value 1 to $Dummy. Used verbatim, this example makes no sense, but imagine a calculation in place of the quoted text that evaluates to produces such a let function as text. Such a calculation could include data from fields in your database to produce variables of a name not explicitly specified in your script.

                1 of 1 people found this helpful
                • 5. Re: Temporary globals?
                  Jaymo

                  Global fields require that they be defined in Manage Database. They can't be created on the fly.

                  1 of 1 people found this helpful
                  • 6. Re: Temporary globals?
                    ezeitgeist

                    To follow up on understanding global variables, if I already have a gSearch that is used in a different layout. Can I use it in this new layout or could there be an issue somehow in Web Direct with users trying to use the global in different layouts at the same time. (Or, in Web Direct, does each concurrent user have their own occurrence of global fields separate from other concurrent users?)

                    • 7. Re: Temporary globals?
                      Jaymo

                      Global fields can be used on any layout at any time without a relationship. The value will be the same on all the layouts as the data is only stored once per session. If you need two different values at the same time then you need two global fields.

                      1 of 1 people found this helpful
                      • 8. Re: Temporary globals?
                        ezeitgeist

                        Okay, so if 2 users are logged in via Web Direct, does that count as 2 separate sessions then? So therefore no need to worry about 2 values at the same time?

                        • 9. Re: Temporary globals?
                          siplus

                          I have a global called gOneSizeFitsAll. (Yes you may laugh). It's in our statistic database, which has one table and one record. I feed it with all kinds of stuff from other databases / tables, via list or via SQL.

                           

                          For mr. Joe User, this global is his personal trainer, barman, dietist, taxi driver and everything else - it's monogamy at its best because he owns this global and nobody else can mess with it. As Joe progresses through statistics and tasks, gOneSize will be cleared and refilled to suit his needs.

                           

                          So, to answer your question, yes, you can use your gSearch for anything, every user is served his own iteration of the global, but its use in scripts will be maybe better understood by others looking at your work if you avoid confining it to the search realm by choosing a "wider" name.

                          1 of 1 people found this helpful
                          • 10. Re: Temporary globals?
                            philmodjunk

                            And the "rules" are pretty much the same for a global variable. They can be referenced on any layout anywhere in the same file for a given session. The key differences:

                             

                            They are only created when a value is assigned to them. They disappear when the file is closed or when assigned a "null" (empty string actually) value.

                            They can't be used to match values in a relationship on the relationship graph

                            They cannot be directly edited by a user.

                            1 of 1 people found this helpful
                            • 11. Re: Temporary globals?
                              Jaymo

                              yes, two users equals two sessions. Global fields work in WebDirect pretty much the same as in a FileMaker client.

                              1 of 1 people found this helpful
                              • 12. Re: Temporary globals?
                                ezeitgeist

                                You all are awesome. Much appreciated for the insights! This has all be helpful in ways you have no idea. :-)