Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In FileMaker Pro 11 Essential Training, Cris Ippolite demonstrates the principal features and functions of this popular database software, including creating tables and relationships, managing fields and records, and working with layouts. The course shows FileMaker developers how to find, sort, and share data as well as how to create reports, calculations, and scripts. It also covers brand new features in FileMaker Pro 11 such as the Inspector tool, charting, and portal filtering. Exercise files accompany the course.
The first set of script triggers that we are going to take a look at are called object based triggers. These are triggers the deal mainly with the layout objects and most specifically, fields, although there are other objects that can affect these triggers. But most of the time, you are going to be dealing with the fields. For example, if you were to click into a field, or click out of a field or modify or save a field value, then that would execute a script and using a script trigger on a field or layout object is a lot more subtle of a trigger than having to rely on a user to press a button, for example, because of course, then you have to train them to do these things and say any time you do this, make sure you hit this button before you leave the layout, and do all that kind of stuff.
So with these triggers, they act more behind the scenes, so quite frankly, you can run activities that the user is not even aware of. Then you don't have to train them to run the scripts. So this is something that's great that users can do something many, many times without them even knowing it's happening and not worry about them remembering to do things. All the triggers will be added to your objects while you're in Layout mode. So let's go in a Layout mode, into our Exercise File, under View > Layout mode, and we are going to want to choose an object, in this case a field.
So let's go to the Notes field, and we're going to select the entire Notes field, and once you have a field selected, you can go under Format to Set Script Triggers which is all the way on the bottom, and also you could right-click or Ctrl+Click to also get to these Set Script Triggers window. In either case, you'll see this dialog appear, and it gives you a list of all of the different Script Triggers that are available to you, to be able to assign to an object. So let me briefly describe each one of these triggers, and what they would do if you chose it.
So, the first one, OnObjectEnter; this triggers the script to run when the object becomes active. So, for example, there are several actions that could activate an object, such as tabbing or clicking to an object, like a field, or even tabbing into a Tab control, for example. The OnObjectEnter event can also be triggered by a Script Step that enters a field. So if you have a script that says Go To Field, then entering that field will cause another script to run. So sometimes you got to be a little bit careful with the combination of these things, especially if you are adding Script Triggers to an already existing database.
Tabbing to a button or a tab, not field, but just buttons or tabs, will activate the trigger, but clicking in a button or tab does not; however, clicking in a field will. Next you have OnObjectKeystroke, and this triggers a script when an object is active and a keystroke is received, meaning anytime somebody hits the F key, run a script. This is a little bit more of a advanced trigger,s since it involves a lot of scripting and calculation and understanding to get it to work, so consult FileMaker Help for details. And it's a little outside the scope of this title, but it might be of interest to you, if it sounds like that's something you could either with.
It's called OnObjectKeystroke. OnObjectModify triggers a script to run when the value of an object changes. So the value inside of a field, for example. Actions that triggers this event include things like typing in a field, selecting a check box, cutting and pasting into a field, or script steps like Insert Text. Additionally, switching tabs on a tab control will trigger this action, which is kind of interesting. OnObjectSave triggers a script to run after the object's data has been validated and saved but before the field is exited.
So Modify will a trigger script when something is changed, but OnObjectSave won't trigger this script until you click outside the field, validation passes if there is any, and then the field is committed; then it runs. OnObjectExit triggers a script to run before the active object is exited. So if you try to tab off of the field that will trigger a script, for example. Actions that trigger this would be tabbing on to the field, or just clicking on a different object, so you are changing the focus. Unlike OnObjectSave, this trigger will activate regardless of whether or not an object's data has been changed.
So exiting doesn't matter whether or not you have changed something and therefore save. So you got slight nuances to all of these things. But in FileMaker Pro 11, there is a new one called, OnObjectValidate. This triggers a script to run before the field level validation occurs. So, a validation actually occurs somewhere in between when you would make a change, and when you commit the record. So it happens before the record is saved to the database. So this trigger will launch in between those things, and it will do so before the validation so that you get a change to change the data in the field yourself if you would like to.
You could have a script that grabs two digit years and turns them into four digit years before the value even gets saved in the database. As a matter of fact, if you watch the video on the lynda.com Online Training Library called FileMaker 11 New Features, you will see an example of that very technique that I just mentioned. In this example, what we want to do is just simply check the spelling of a field once the user makes a change to value that was in the field and then they leave. So, in that case, we would say something like OnObjectSave, because of course, that's only going to run if something has been changed, and if the user tries to save it.
So let's go in here, and see if we have got any scripts that would fit this. Well we don't. So when the Specify Script Window appears, we can still create a script for this trigger, and we can do so by hitting this little Plus button there. And what we are going to do is name it Spelling and then scroll all the way to the bottom, and we are going to find a Script Step for Check Spelling. And here we go. We have got one for Check Selection under the Spelling section. So let's double-click on that, and it will select the entire contents, and we tell if what field we wanted to check, and we will pick Notes.
So now you see we have an OK button on our script because we are creating this through the Specify Script dialog. So now it's saved for us for automatically because we hit OK. If we hit OK again, we now see that this script is assigned to that object. There is one more decision you have to make before you leave here, though. You don't want to overlook it. You need to decide which mode you want this to work in. So by default, all the triggers for objects will run in Browse mode, and you have the option to also run it in Find mode. Now, this one wouldn't make sense, because if you were in Find mode and you were trying to search for a value inside Notes field, maybe you don't want the spelling to be checked because the user doesn't want their criteria changed.
So we will just leave at Browse mode here. Let's go into Browse mode and see how this works. Now, we have got a piece of data, we have changed the original value, and I am going to click outside the field, And you see that it makes the Check Spelling dialog pop up. So back in Layout mode, you will notice that in the bottom right-hand corner, there is a layout badge for including in Quick Find, which is the green magnifying glass, but now also you see that there is a little script icon with sort of a paint ball splat next to it.
That indicates that this field has a Script Trigger assigned to it. So you will notice that if I go in here, right-click or Ctrl+Click, and remove the Script Trigger, that that badge disappears. Let's look at another example in this same file. So let's say in this case we are having trouble losing our original contact information. So, for example, people are coming in, and they are changing the first and last name of the contact, but we are losing who the old contact was, in case we want to follow up with somebody or in case we are trying to remember who a person was, and where they used to work even after they are gone.
Well the problem with that is is after you change your name, it's automatically deleted from the database because it gets committed to the database. So let's say we have got some scripts that we have created, under Manage Scripts, and one of them is grab the existing full name. And if you remember in a previous movie, we talked about the concept of a variable, which is like having your own mini clipboard, and inside that clipboard, you are going to save a certain value. And the value we are saving in this case was the original full name of the person, and we are going to set it to a place in memory.
That's just one script with one step. Then we have another Script Step here called Create Log. This one is a little bit more complicated. Feel free to check this out when you have a little bit more time, but it uses a lot of these variables, but essentially what it's doing here is committing the record, then setting a variable with the new name that was just made. So if you change it from John Smith to Bill Jones, it's going to save the Bill Jones. And then it's going to the object, which is a Script Step that allows us to navigate to a object that has been named in Layout mode, and in this case, it's a Notes tab, and it's going to set a value in the Notes field that includes the value that's currently in the Notes field along with the old value and the new value and then go back to where you started.
Now, this script is intended just to demonstrate the OnObject trigger. This is certainly a more intermediate or advanced scripts, but I urge you if you are interested or curious to take a look at this, feel free to open up the Exercise Files and poke around in the script and see how it all works. What, we are going to do in this case is we are going to go into Layout mode and you understand that the two scripts that we have got - well I am going to go here, and I am going to pick the ContactFirstName, and I am going to right-click or Ctrl+Click on Mac, and I am going to choose Set Script Trigger.
Now, in this case I have to figure what's going to trigger the script? Well the whole idea here is that if somebody saves a new name, so really it doesn't have to deal with if they click into the field, then if they modify, we really don't want to do it right when the modification happens, we want to do it after they have done all the changes and then hit Save. The problem with Modify is it will trigger the second you hit any keystroke. So, how about OnObjectSave? Any time they are trying to save a new change, we are going to say, CreateLog, and what you might not be aware of is that you can assign multiple script triggers with different scripts to the same object.
So in this case, sure, that's great that we are creating a log when we hit Save, but how about when we Enter the object. We are going to grab the existing full name. So, now what we are doing is when a user clicks into this field, and makes a change, it's going to grab the name that was in there before they make a change. And then after they make a change, it's going to grab the new name, and it's going to go into the Notes field and paste all that information in there for us. So, let's take a look at how this works. You will notice the layout badges. Go into Browse mode. Save our changes.
Let's go and change the name. So here I have entered the field I am modifying. I haven't saved it yet, as you notice if you look over Notes, now that I have switched over to Notes, what I have done is I have committed my change. So I didn't have the change committed by clicking outside the field, but switching over to another tab committed it. So, now you see before where we had sample notes. Now it says the previous contact name was, and then it gives the timestamp of when that happened.
So, for example, I could change it again. This time I will click outside the field. Now you see another line has been added. The previous contact was Cris Ippolite, and so on. So, in this case, this is something where a user might not even know what's going on, but they can make all the changes that they like, and all the while a log will be recorded. So if you are interested in the script, I know it's a little bit beyond essential training, but feel free to take a look at it, or even copy and paste it to your solution and see if you can get it to work to add a little bit of logging functionality. So, as you can see, object-based triggers are extremely useful. They can be used one at a time, assigned to fields, or layout objects, or even several different triggers can be assigned to the same object.
So, now let's move on and take a look at some layout-based triggers in the next movie.
Find answers to the most frequently asked questions about FileMaker Pro 11 Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.