Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

get_params

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 3.7  (49 votes)
  Discuss this Custom Function

steve harley, paper-ape
http://ihavenowebsitethanks.com

automatically turns named script parameters into local variables

Sample Input:
If [ get_params ]
Sample Output:
returns 1 for success or 0 if parameters were malformed

(operates via the side effect of creating local variables for each script parameter)


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

this function supports a powerful technique for passing multiple/optional named parameters to scripts; it is specific to FM8+, and relies on the feature that Let() can create local (and global) script variables, even from a within custom function

the principle is that a script is called with a string parameter of the form

"$param_name1 = value1 ; $param_name2 = value2"

the parameter string will be wrapped with Let() and Evaluate(), using the well-known technique of passing multiple named parameters; however since the names are prefixed with "$", the ordinarily "temporary" variables created will instead persist outside the Let() to become local script variables

if the evaluation succeeds, get_params will return 1; if there is an evaluation error (usually because of a malformed parameter string), Let() returns an undefined value, hence the test for equality to 1 (it's not as redundant as it seems), so my pattern is to call get_params() within an If statement at the top of a script both to automatically set local variables and to catch gross errors in the parameter string

the script that receives the parameters may preset a default value of a local variable prior to calling get_params, and if the variable is defined in the parameter, it will override the default; if the value is not defined, the default will prevail, thus one can intuitively specify optional parameters to a script

the main limitations have to do with the fact the overall script parameter must be a string; within the string, escaping of substrings is necessary; the general case is illustrated by this parameter, from which get_params will assign to the script variable $num_files a numeric value of 3 and to $filename_prefix a string value of "foo"

"$num_files=3;$filename_prefix=\"foo\""

another issue is that, due to an Evaluate feature, line ends within parameter substrings are converted to spaces; substitution of a proxy character (such as a vertical bar) is the recommended work around

i use this technique along with a naming scheme for scripts which includes the parameter names and whether they are optional; for example a script might be named

create_files($filename_prefix[; $num_files=5])

which indicates the two parameter names, and that if $num_files is omitted it will take a default value of 5; i find this naming scheme, in addition to being self-documenting, makes it much easier to remember the parameter names while setting up the parameter in a Perform Script step

in this case the script might read:

Set Variable [$num_files; 5 // the default value]
If [not get_params()]
// handle an error with the parameter string (i usually log it and return a fail value from the script)
Else
// normal processing; param values are now defined; the rest is just example and is not relevant to the concept
Loop
Exit Loop If [$num_files < 1 // default value or passed value]
// other actions here
Set Variable [$num_files; $num_files - 1 // decrement loop counter]
End Loop
End If

(i would ordinarily avoid changing the value of script parameters, but in this case it makes the example simpler)

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

There are no comments yet. Be the first to post a comment about this Custom Function! Please try to keep it brief & to the point. Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 9 + 6 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions