Product Logo


Trigger and schedule scripts

Immediate Events


Immediate Events example database

This example demonstrates the MMScript_CreateImmediateScriptEvent function which calls a script immediately. It can be used for all sorts of interesting things. For the purposes of this example, we are going to keep things very simple as this is an introductory example. For more complex examples, check the Example Library site often or subscribe to one of our RSS feeds for updates.

To begin with, take a look at the function prototype:

MMScript_CreateImmediateScriptEvent( Script {; DB {; EventName {; EventValue {; Priority {; CurrentScript }}}}} )

A function prototype is basically the format of a function. In the above example, note that there are several optional parameters indicated by curly brackets. This means that a function can take on different forms based on what you need to do.

Though there are six possible parameters for the MMScript_CreateImmediateScriptEvent function, only the “Script” parameter is actually required. For example, you can call the script “MyScript” in the current database as follows:

MMScript_CreateImmediateScriptEvent( “MyScript” )

Likewise, you could call the script “MyScript” in the “MyDatabase” database pass a script parameter using the following example code:

MMScript_CreateImmediateScriptEvent( “MyScript” ; “MyDatabase” ; “MyEvent” ; “My ScriptParameter value” )

Download Example File

FileMaker 7–11 Example

FileMaker 12 Example

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.

How to recreate in your solution

To reproduce any of these buttons, enter layout mode and create a new button on your layout. Choose “Set Field” from the list of button steps. Click the “Specify” button next to the “Specify target field” check box. You can use any text field for this step, though you may want to create a special field named “Result” specifically for use with plug-ins. This makes it simple to view plug-in results be keeping an eye on this field. Finally, click the “Specify” button for the Calculated result. Try copying and pasting the example calculations discussed in this example to get you started.

To reproduce the “Beep” and “Beep Too” scripts, open the ScriptMaker and click the “New” button. Name the script “Beep” or “Beep Too”. For the purposes of this example, both scripts are virtually identical. The only differences are the dialog names. In a real life example, these scripts could do whatever you desire. Add the “Beep” script step, and then the “Show Custom Dialog” script step. With the “Show Custom Dialog” step selected, click the “Specify” button to set up the dialog. Set the title of the dialog to “The "Beep" script has been triggered…..” or “The "Beep Too" script has been triggered…..” depending one which script you are working on. Finally, set the calculation for the “Message” to the following code:

Case ( Get ( ScriptParameter ) ≠ “” ; Get ( ScriptParameter ) ; “The "Beep" script has been triggered” )

The above calculation simply checks to see if there is currently a ScriptParameter. If there is, it uses the ScriptParameter for the message. If the ScriptParameter is empty, then the default message is shown. Remember to use “Beep Too” for the “Beep Too” script.