FM - Passing More than One Variable in an Exit Script Step

I have created the subroutine below, since it is used in 3 different email scripts.  Rather than changing all the local $ variables to global $$ variables is there a way to pass more than one variable through the Exit script step?  I'm considering this because I've heard that global variables don't close until FM closes and thus uses a bit more RAM.  Thanks.
LVL 2
rvfowler2Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Will LovingConnect With a Mentor PresidentCommented:
There's a really great way to do this that involves a simple custom function called "GetParameter()". It supports infinite user defined Script Parameters. For your multiple script parameters, you create a carriage return separated list in the following format:

List(
   "Parameter1=" & <the parameter value> ;
   "Parameter2=" & <the parameter value> ;
   "Parameter3=" & <the parameter value> ;
)

Then, in your script you simply use the Function GetParameter( "Parameter1") and it gets the value for whatever came after "Parameter1=" in the list up to the next carriage return. The Custom Function is as follows:

GetParameter( ParameterName ) =

Let(
   [
      ListOfParameters = "¶" & Get ( ScriptParameter ) & "¶";
      linestart = Position ( ListOfParameters ; "¶" & ParameterName ; 1 ; 1 ) + 1;
      paramstart = Position ( ListOfParameters ; "=" ; linestart ; 1 ) + 1;
      paramend = Position ( ListOfParameters ; "¶" ; linestart ; 1 ) - 1;
      paremlength = paramend - paramstart + 1;
      ValueOfParameter = Middle ( ListOfParameters ; paramstart ; paremlength);
      ValueOfParameter = Trim(ValueOfParameter)
    ];

ValueOfParameter

)

You can find more information on this Custom Function at: http://www.briandunning.com/cf/577
0
 
rvfowler2Author Commented:
Attachment.
-PassingVariable.JPG
0
 
Will LovingConnect With a Mentor PresidentCommented:
Here's an example of how I might use this with an email script. The script parameter might look something like this:

List(
"EmailAddress=" & Contact::Email1 ;
"EmailAddressCC=me@mydomain.com" ;
"EmailSubject=" $EmailSubject ;
"AttachmentPath=" & $FilePath
)

You'll notice two things here: 1) Parameters can reference fields (Contacts::Email1), variables ($EmailSubject") or just be entered text and 2) I didn't include the EmailMsgBody either as a field or variable. It's possible to do this, however, the issue is that email message almost always contain carriage returns and this is a return-delimited list. So, the way to include the Email Message Body is to wrap it in a Substitute statement that changes all carriage returns to something else like a single or double pipe "||". When you extract the passed variable in your generic email script you just need to reverse that process.

You also mentioned passing parameters on script exit using the Exit Script [] script step. This works exactly the same except that you need a slightly different Custom Function to extract the script parameters. I've created just such a custom function called GetResultParameter() - just a variation on the one above - that does this. It's available at: http://www.briandunning.com/cf/1202   So, instead of using Get( ScriptResult ) you use GetResultParameter() and it allows you to pull multiple named parameters just like GetParameter()

GetResultParameter ( ParameterName ) =

Let(
   [
      ListOfParameters = "¶" & Get ( ScriptResult ) & "¶";
      linestart = Position ( ListOfParameters ; "¶" & ParameterName ; 1 ; 1 ) + 1;
      paramstart = Position ( ListOfParameters ; "=" ; linestart ; 1 ) + 1;
      paramend = Position ( ListOfParameters ; "¶" ; linestart ; 1 ) - 1;
      paremlength = paramend - paramstart + 1;
      ValueOfParameter = Middle ( ListOfParameters ; paramstart ; paremlength);
      ValueOfParameter = Trim(ValueOfParameter)
    ];

ValueOfParameter

)
0
 
rjplusConnect With a Mentor Commented:
Sometimes it easier to explain solutions to problems by viewing examples.  I have therefore attached a modified file originally created by FileMaker Guru, Darren Terry to demonstrate one of many ways to pass multiple parameters.  This particular technique was created by John Sindelar, Seedcode.  
I can also recommend the system used by Geoff Coffey at Six Fried Rice - using custom functions (this is my preferred method).  Hope this example file helps to illustrate the technique? Parameters.fp7
0
 
rvfowler2Author Commented:
Theory and example looks good.  Will eventually implement, but caught up elsewhere right now.  Thanks to both.
0
All Courses

From novice to tech pro — start learning today.