Example Explanation
This example consists of three buttons which utilize the “Set Field” button step. The MMScript_CreateImmediateScriptEvent function is used in various ways, and feedback is returned to the “Result” field.
Call "Beep"
The “Call ‘Beep’” button simply calls the script “Beep” when activated. Keep in mind this example is for demonstration purposes. It will become clear in the explanation of the following buttons why you would want to do this. The calculation for the “Call ‘Beep’” button is as follows:
MMScript_CreateImmediateScriptEvent( “Beep” )
The plug-in will return the following to the result field:
Called ‘Beep’ in ‘Immediate Events’.
Call "Beep" & "Beep Too"
The “Call ‘Beep’ & ‘Beep Too’” button actually calls two scripts, “Beep” and “Beep Too” using only one calculation. So now we have an immediate advantage over the built in “Perform Script” button step because we can call several scripts in one shot just from a button. This concept can be used anywhere you can access a calculation box. For more on this topic, there is a section in the MMScript documentation called “Places to use MMScript Functions” which is under the “Coding Considerations” tab. You can view the documentation by opening the MMScript.fp7 database that comes with the MMScript download archive.
The code for this calculation is as follows:
MMScript_CreateImmediateScriptEvent( “Beep” ) & “¶” &
MMScript_CreateImmediateScriptEvent( “Beep Too” )
The plug-in will return the following to the result field:
Called ‘Beep’ in ‘Immediate Events’.
Called ‘Beep Too’ in ‘Immediate Events’.
Call "Beep" or "Beep Too" (Time Sensitive)
So far the buttons have been extremely simple, so to finish off this example we will create a calculation that is a little more complex. The “Call ‘Beep’ or ‘Beep Too’ (Time Sensitive)” button calls a script depending on what time of day it is and passes a script parameter depending on what time of day it is.
// If it is before 12 PM call the “Beep” script, otherwise, call the “Beep Too” script.
// This calc also passes a script parameter to the desired script.
Let (
[
theScript =
Case ( Get ( CurrentTime ) < GetAsTime ( “12:00:00” ) ; “Beep” ; “Beep Too” );
theScriptParameter =
Case (
Get ( CurrentTime ) < GetAsTime ( “12:00:00” ) ; “It’s before lunch.”;
“It’s after lunch.”
)
];
MMScript_CreateImmediateScriptEvent(
theScript ;
Get ( FileName ) ;
“Time Sensitve Script” ;
theScriptParameter
)
)
The plug-in will return the following to the result field:
An Immediate Script Event named ‘Time Sensitive Script’ has been created.
The above code makes use of a Let statement, which really makes things easy to read and update.
The first thing we do is create the “theScript” variable which checks to see if the current time is before noon. If it is, the value is “Beep”, otherwise the value is “Beep Too”. This variable is used to hold the name of the script when we use the MMScript_CreateImmediateScriptEvent function.
The second thing we do is create the “theScriptParameter” variable which also returns a value based on the time of day. If it is before noon, the value is “It’s before Lunch”, otherwise, the value is “It’s after lunch”. This actually gives us no time for lunch, but that is beside the point. :)
Lastly, we use the MMScript_CreateImmediateScriptEvent to trigger the script. We use the “theScript” variable for the script to call. The built-in FileMaker “Get ( FileName )” function is used for the database name. This is useful because if you ever decide to rename your database the calculation will automatically work. We used “Time Sensitive Script” for the EventName parameter. This is useful because the plug-in will return information about this function call using this name. Finally, we use the “theScriptParameter” function for the ScriptParameter or EventValue parameter.
