1 of 1 people found this helpful
Global fields are largely used as "session" variables. They have one value across the entire table and it is only valid during a particular session when a user is logged in. So they differ across various users. You can also use variables $temp or $$temp in a similar manner today. Global fields were used more when variables didn't exist. You can also access global fields across table relationships.
Script Parameters allow you to pass information to a script so that it can act on the information passed. You can pass this information to the script through use of a global field or $$temp variable...but it requires more documentation and management of those variables to make sure that they are not used in other places that would cause issues with the scripts you're calling.
Hope that helps,
1 of 1 people found this helpful
Can someone also please tell me what are the advantages of using Script Parameters within a 'Perform Script' that is called by a button; in conjunction with using the "Get(ScriptParameter)" function within a subscript. Seems to me it does nothing more than replacing a variable or constant within a calculation called by the parent script (as opposed to just declaring the variable or constant).
I'm not seeing the benefits but I'm sure there are some valid reasons that experienced developers use these techniques that make it worthwhile.
In programming your variables should never live past their scope. That is why you typically wouldn't declare $variables or $$variables in a calc, or use a $$variable just so you can use the value in two scripts; you declare the $variable in one script and pass it along ot the next one as a parameter.
The benefit of this is that memory gets cleared automatically at the end of the scope (when a calc is done, when a script ends,...) and you don't have to manually clear out any variables that you have declared. There is also much less chance of errors that way, easier troubleshooting and maintenance,
As a side benefit your data viewer display will always be clean and uncluttered with $$variables that have no meaning for the process that you are currently debugging.
It is a good practice to get into, it creates good coding habbits.
Thank you for the replies. You have both been helpful in helping me understand the concept on when to use global variables and script parameters.
on 2013-05-16 12:50 prtechwork wrote
Can someone please tell me what are the benefits of using Global Fields as opposed to making a typical field that is hidden from the end user and used soley for calculation purposes?
others answered on the benefits of script variables and parameters over global
fields, but it seems to me you are asking for the benefit compared to
non-global fields … a global field has one value for all records in a table,
and its value is accessible from anywhere in the database even if there is no
relation from the base table of a layout to the table containing the global; a
non-global field is specific to a record, and can't be accessed when the
associated table is not related
when a global field value is changed, only the user who changed it sees the new
value; if a file is hosted by FileMaker Server, changes made to global field
values during a session are not remembered when a file is reopened
global fields can be used to set up some special types of relations which
independent of the selected record on the global end of the relation
Can someone also please tell me what are the advantages of using Script Parameters within a 'Perform Script' that is called by a button; in conjunction with using the "Get(ScriptParameter)" function with a subscript. Seems to me it does nothing more than replacing a variable or constant within a calculation called by the parent script.
using a parameter uncouples the value passed from the script definition; you
seem to realize that when you describe a parent script and a subscript, but
here's an example that spells it out:
suppose you have a layout with five text fields and five buttons; each button
needs to pass the value of its adjacent field to a script; with script
parameters, you can simply specify which field value to pass in the button
setup, but without script parameters, you'd need five additional scripts each
hard-coded to put the value of a specific field into a global variable (or
field) before calling the main script
script parameters in general (whether used with a button or not) also have the
advantages others mentioned, plus they facilitate recursion
that said, the way FileMaker implements script parameters is a bit more awkward
than typical programming languages, so it may put some people off
Wow! Great and informative answer.....Very much appreciate it!. Thank you Steve.