Note: This is a more complex one, so if you are beginning with script triggers, it is maybe a good idea to try an "after update" event first... Also, make sure that a simple FileMaker button placed on your field on the layout is not doing the same job correctly...
Here are some basic tips about implementing before-update triggers on a text, a number, a date, a time, a timestamp or a container field!
So the idea is to monitor the event when a user is placing his computer's cursor into a specific field, then trigger a script before the field can actually be entered. This is the "before-update" event.
First, create a new privilege set as FileMaker doesn't allow modifications to the built-in sets([Full Access], [Data Entry Only] and [Read-only Access]). Actually, we need to customize something in the privilege set for the before-update trigger to happen...
To accomplish this, there is many mouse clicks but it is not that complicated. Go on the 'File' menu then 'Define...', 'Accounts & Privileges', then go on the tab named 'Privilege sets' :

Select the privileges set called "Events" or create a new one if it doesn't exist yet. The permissions you are going to configure will apply to all future users of this 'group'.
Once in the 'Edit Privilege Set' dialog, go under the permissions in the 'Data Access and Design' section and choose under the 'Records' dropdown the item called 'Custom Privileges' :

Then choose the correct security intersection where the X axis is the user's action and the Y axis is the table you want to monitor.

For the desired action, go under the corresponding 'limited...' item under the record-editing permission. And you will be prompt with the familiar calculation dialog box. This is where you can enter your condition and the trigger statements.
It is a good idea to place an IF or Case statement if you want your before-update script to be triggered only when users enter specific fields.
Example calculation :
If ( Get ( ActiveFieldName ) = "YourInputField" ;
// Then
1 & S4HU_EventScript ( Get(FileName) ; "YourBeforeUpdateScript" ; "" );
// Else
1)
See the calculation below :

The '1' are required. they are telling FM that the validation rules are ok. We are only using the pre-validation event to place the EventScript call, we aren't really validating data at this stage.
Finally, you should assign which users will have this new privileges set. This is a 'role-based' schema so you can, for example create a new 'Events' privileges set and assign all the account/persons that should have this role in your application (clerks, sale reps, etc.) The users who belong to this 'Events' privileges set will have the script triggers while other users who belong to other privileges set won't necessary get all these triggers.
TEST DRIVE !
When a user of this privilege set place his cursor into the field called "YourInputField", by using the tab key or directly when entering with his mouse...
then the target script named "YourBeforeUpdateScript" will be triggered each time :

(The calculation proposed in our example file is checking first for the correct launching of the before-update script. For purposes of this tutorial, the calculation here is a lot simpler)
Please note that a trigger built inside the security features will work on every layouts of your FileMaker file. This is an advantage over individual buttons.
top
|