Top Banner
Script Triggers FMUG February 5, 2010
24

Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Aug 08, 2018

Download

Documents

duonghanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Script Triggers

FMUGFebruary 5, 2010

Page 2: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

What We Will Cover

• What is a script trigger?• Key components of triggers• Examples• Gotchas• Best Practices• Resources

Page 3: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

What is a Script Trigger?• A database trigger is procedural code that is

automatically executed in response to certain events on a particular table or view in a database. (Wikipedia)– Triggers are a common database application

programming feature– Just about every database technology has some

version of this feature

• Script Triggers in FileMaker Pro 10 allow you to automatically run scripts based on user actions like entering a field or inputting data. (FMI web site)

Page 4: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Script Trigger Overview

• New feature introduced in FileMaker version 10

• One of the tools available to control the user’s environment

• Allows the developer to streamline the user experience – Less clicking required

Page 5: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

The Components

• The Event, or “Trigger”• The Script• The Timing Around the Event• The Associated Layout and Object

Page 6: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

The Trigger• The occurrence of an event triggers a script to run• Usually involves user interaction• Some FileMaker events that can trigger script execution:

– After a field is entered– When typing into a field– After a value is changed– Before data is saved– Before exiting a field– When a layout becomes active– When navigating from record to record– Before a record is committed– When an uncommitted record is changed back to its original value– When changing from Browse, Preview or Find mode

Page 7: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Trigger Categories

• Object – “Object” includes interactive elements like fields and tab controls;

not labels or lines– For example, a user may:

• enter or exit a field by clicking or tabbing• modify the value in a field

• Layout– For example, a user may:

• commit a record• switch layouts• change from Browse mode to Find mode

• File Open or Close

Page 8: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Trigger Timing

• Triggers are fired either before or after the event occurs– Pre-event triggers

• Examples: OnRecordCommit, OnLastWindowClose, OnModeExit

• Can cancel the event if the script returns a “false”

– Post-event triggers• Examples: OnLayoutLoad, OnObjectModify

Page 9: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Fire Order

• Order in which triggers fire:– 1.OnFirstWindowOpen– 2.OnLayoutLoad– 3.OnModeEnter– 4.OnRecordLoad– 5.OnObjectEnter– 6.OnObjectKeystroke– 7.OnLayoutKeystroke– 8.OnObjectModify– 9.OnObjectSave– 10.OnObjectExit– 11.OnRecordCommit or OnRecordRevert– 12.OnModeExit– 13.OnLastWindowClose

Page 10: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

The Layout

• Most triggers are dependent on user interaction with a layout

• You may configure:– Many triggers per layout– Many triggers per action

• So note the fire order– But only one script per trigger

• How to implement a trigger• How it looks to the developer

Page 11: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Configuring Object Triggers

• Select an object in Layout mode, • Navigate to Format > "Set Script Triggers " • This will open the configuration window for

Object script triggers. OR• Access the configuration window by right-

clicking (control-clicking on Mac) an object, and selecting "Set Script Triggers "

Page 12: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Figure 1: Object Trigger

Page 13: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Configuring Layout Triggers

• Layout Triggers– In Layout mode,

navigate to Layouts > Layout Setup

– Click the "ScriptTriggers" tab.

Page 14: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Configuring File Triggers

• Navigate to File > File Options

• Enable the "Perform script:" option under the "When opening this file“ section and the "When closing this file“ section.

Page 15: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Trigger Visual Indicators

• Objects with triggers display a red “firecracker” in Layout mode

Page 16: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Layout Trigger Indicator

• There are no visual cues for layout triggers• You must run a Database Design Report

– You can see both in the DDR

Page 17: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Examples

• Sort on load• Find dropdown• Navigation• Show duplicates• Data Entry warning

– Cancels Event– Not for validation

Page 18: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Gotchas• Actions that are not triggers:

– Non-interface-based changes to data:• Importing data, script action on a field (setfield),

schema changes, Replace• Lesson: Don’t use triggers for data integrity

• Maintenance– Associated with layouts and objects

• Not centrally catalogued like scripts and layouts• DDR is the only way to know where they all are

– Lesson: Have a good reason for every trigger, not just “‘cuz it’s cool”

Page 19: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Another Gotcha

• Infinite loops– If a pre-event trigger fires a script that causes that same

pre-event to occur on the same object, the script will be executed endlessly

• Example: a script triggered OnObjectKeystrokecontains script steps that cause focus to leave and then return to the same trigger-associated object

– Lesson: Avoid infinite loops

Page 20: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

One More Gotcha

• Backwards compatibility– Triggers will not function (except for File

triggers)• You’ve replaced all your navigation buttons with

dropdown lists! Now what?– Triggers will be preserved if objects with

triggers are duplicated in an earlier version, but not with copy/paste

– Lesson: Don’t mix versions if you’re using script triggers

Page 21: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Best Practices

• Test extensively• Never implement new triggers directly on a

production system without testing thoroughly first in a development/test environment

• Use FileMaker Pro Advanced– Script Debugger– Database Design Report

• Always have clean backups and clones

Page 22: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

And If All Else FailsUse File Recovery advanced options to check off “Bypass startup script and layout”

Page 23: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Cecilia’s Opinion• Be careful with mixing triggered navigation

with other methods like buttons– Your users may experience inconsistent results– With mixed methods, maintenance could be a

nightmare --not to mention reverse engineering– Do your best to document your use of triggers

• Don’t replace perfectly functional existing feature implementations with triggers unless it really adds value --like automation!

Page 24: Script Triggers - Information Systems & Technology Triggers.pdf · the "When closing this file“ section. ... – If a pre-event trigger fires a script that causes that same pre-event

Resources

• More about database triggers:– http://en.wikipedia.org/wiki/Database_trigger

• Script triggers in FileMaker:– http://www.filemaker.com/products/filemaker-

pro/script_triggers.html– FMI Knowledgebase

• http://filemaker.custhelp.com– White paper available to TechNet members