Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Passing multiple script parameters

Featured Replies

Posting this with permission from SeedCode. I have seen similar methods that require an additional function to pass the parameters in, but it doesn't seem to me to be an improvement. I've also seen methods that require more complex structuring of the parameter. What I like about this method is that once you create the function, it is so simple to use.

I call a script, and for the script parameter, pass in as many name/value pairs as required, e.g.

"id=" & IDfield &

"; name=" & nameField &

"; type=widget" // etc.

At the top of the script, I generally start with:

Set Variable( $param ; Get( ScriptParameter ))

... and then parse out the parameter values using the function below, which I call GetNamed:

Set Variable( $id ; GetNamed( "id" ))

Set Variable( $type ; GetNamed( "type" ))

(FWIW I've noticed in recent SeedCode files that they've replaced this CF with a script that does essentially the same thing.)

/* SeedCode_GetValue

Created by John Sindelar, SeedCode LLC

www.seedcode.com 

Creation Date: 13 Feb 2005

Last Modified Date: 21 Feb 2007  

 

Purpose:   

Extracts a value from a set of Name/Value pairs in a text string (such as a variable or field).

Where "Name" is the name in a Name/Value pair like: "Operation = Begin". 

Separate Name/Value pairs with semicolons like: "Operation = Begin ; Status = Estimate". 

Quotes are optional in the value: "Operation = Begin ; Response = \"OK\"" 

Fields can be entered like this: "Operation = Begin ; Status = " & job::status 

If a requested value is not present, the result is blank. 

 

Parameters:   

Text: the string within which you're looking for your value. Normally this is your variable or global field.  

Name: the name in the name / value pair you're looking for. 

 

Example: 

Given  this string in a variable called $Var: "Operation = Begin ; Status = Estimate". 

The following will return "Begin":

SeedCode_GetValue ( $Var ; "Operation" )



Requires Other Custom Functions:

None



*/ 



Let ( [ 

string = Substitute ( Text ; [ "\"" ; "^^" ] ; [ " ;" ; ";" ] ; [ ";" ; "\" ;" ] ; [ "= " ; "=" ] ; ["=" ; " = \"" ] ; ["¶" ; "~~" ] ) & "\"" ; 

eval = Evaluate ( "Let ( [" &  string  & "] ;" & Name & " )" ) ; 

result = Substitute (  eval ; [ "^^" ; "\"" ] ; [ "~~" ; "¶" ]  ) 

] ; 



If ( result ="?" ; "" ; result ) 



)



// End

  • 1 year later...

I've been trying this process out and it seems to work well for short variables. However, for very long variables (in my case the contents of a 2000 line batch file), performance is very slow, taking a good few minutes for the variable passed to be made available to the script.

For now I'll put the file contents into a field earlier in the process, but if anyone knows of an efficient way of passing long variables between scripts without having to go via a field, I'd be interested to hear it.

Alec

  • Author

You may want to use a simple list of parameters rather than this function. Certainly the stripping/restoring of carriage returns is a performance hit when you have thousands of them. When including a multiple-paragraph variable in a list, you'll need to enclose it in a Quote function.

Alternately, if the variables are being used within a single file, you might just want to put them one at a time into global variables. For multiple files, you might have a script in the target file that handles that.

  • 3 years later...
  • Author

UPDATE: we still use this custom function for passing multiple parameters. Recently we had to modify it because we're doing some work with HL7 (a medical coding system) and it uses the '^' and '~' characters, which are used in this CF as placeholders for quote and paragraph characters. Note that HL7 also uses pipes, which I know some folks like to use as "safe" delimiters -- not safe here!

As a quick fix we opted to use a more obscure placeholder. We opted for a couple of currency symbols, ££ and ¥¥. You'd theoretically never see two of those in a row, and we never work with foreign currency so this is satisfactory for us. Obv. you can use your imagination to choose what is appropriate for your solutions.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.