Save a Found Set / Loop with Global
Subtitles of the Movie
When you're creating a future for FileMaker solution, especially when you're scripting, it's a good idea to come up with a variety of approaches so you can choose the best solution for the given scenario, that's because once you learn a technique, that doesn't mean it works best in every scenario. It's about choosing the right approach for the right situation. And let's apply this technique or this approach to the marking records we learned about in the Intermediate tutorial. So let's take a look at what we have and work with that and see if we can think of a different approach. So, let's go into ScriptMaker and we'll come down into our Miscellaneous area and then down into Found sets and there's our Found set saved. Let's edit that. And if you remember we had a Go to Layout, then we copied all the records, so it copied all the serial numbers because that layout only had a serial number field on it, and then we pasted into the Global field X Serial. This works fine. It's very simple, very easy, but it's not necessarily the best approach, or at least it's not the only approach. So let's erase everything except for the Allow User Abort, and let's try a different approach. Let's try a loop. And we're going to throw in some Go to Records in here, Go to record first, and Go to record next, and then of course, exit after last. Now, as we learned, it's a good idea to do a new window here. So we're going to go and find our New window script step, move it over, put it right there, and then we're going to choose Close window. Now, again, the reason why we do this is because when you're looping through records you change the current record. So if we open a new window, do the loop, and then close the window, the person doesn't see that new window open up, but what happens is they get, they really are stay on the same record; they seem like nothing ever happened, or their context hasn't changed, and that's really a great thing. Don't change their context unless you have to. So, that's a great little addition; very easy to do. And then, of course, we're going to have a Freeze Window in there, so we'll move that in there. That'll make the script much faster, so we'll throw that in there, and then we need a Set field in here. The Set field is what's going to build up our return separated list of serial numbers. So we're going to specify that X Serial. Let's see if we can go find it; there it is. So that's going to be our target, the X Serial Global Field, just like what we pasted into in the previous technique we were using. And then we'll say, again, X Serial, we're going to refer to the target field inside the formula so that we can keep the content so that we can build it up, and then we'll concatonate the paragraph return symbol, and then we're going to add in there the primary key. There we go. So each time we add on a return in the primary key, we're going to keep all the data that was in X Serial, so we'll build a return separator list just like you did with Copy all records. And of course we need to duplicate this and initialize this value somewhere up here, instead of this formula you want quote quote. So our target is still X Serial but we want to initialize because if we don't then all the Serial numbers from the last time we saved a found set will get built up and saved in this new found set. So we want to prevent that from happening. And then it's very important for you to clean up your return separated lists. It's not really going to effect the multi key when we try to restore the found set, but if we have an extra return in there it could mess up how we're working with it if we ever decide to manipulate it later. So what happens is, the first time we run this we initialize it, right? We come in here and we say X Serial is our target, put in X Serial which has nothing, then put a return and then put the Invoice ID. Well, that makes a return at the beginning that's not standard for a return separator list. When you start looking at return separated lists there's a value, then a return, a value, and a return, and after the last value there's no return and so before the first value there's no return. So we want to clean that up just to, to really make it look nice and neat, and again, it's not going to effect our multi key but it will help us in organizing and making that a neat, clean multi key for us; neat, clean return separated list. So all we have to do; it's very easy, and we'll get to learn a nice new technique. We say Set field, we go find our X Serial, and we refer to X Serial again, but around it we put left words; left words open parens semi-colon; then we put a really large number. I'll put nine nines 1-2-3, 1-2-3, 1-2-3, and then a close parenthesis. So the idea here is that a return is a word separator just like a space is. There's lots of different types of word separators and when you say grab essentially all the words because we have such a large number here, it's grab all the words, it's going to get every single one. What it does is it says, I only want to grab the separators that have a word on the left and the right side of it. If that separator is not surrounded by two words then we're not going to keep it. It's just how the algorithm of the Words Function works; whether it's left words, right words, or middle words, and now you have to watch out about this technique because it is possible for it to remove data that you want. But I know what kind of data's in here. I know what's in my serial numbers and this won't have any adverse effects on it. All it's going to get rid of is the leading return or any trailing return if there happened to have been one; so, a great little technique. We'll close this. Hit Save. Close it again. Let's try it out. Now, let's first check, though, what's in our X Serial field. We have these values, so we'll go back into our Invoices form, and now we don't have our script attached to a button yet, but we're really not done with it, so we're not ready to attach it to any type of button in our interface. But we can go ahead and run it directly from here, and you'll see that this little Play button down here will perform it right from ScriptMaker. And you can see we've stayed on the same record. We get a little bit of blinking. Let's check out Paste Serial. And you can see now we have more values here. We have every single value inside our invoices, so it has worked properly and there's no leading return so it's taken that out as well. So, a great little solution, and what we're going to do is take a look at a few more solutions, and eventually compare and contrast all of them: the Copy, ah, records scenario, we're going to try the looping global fields, and then any other technique we've looked into while we're working with this Save Found set records technique.
Tutorial Information
| Course: | FileMaker Pro 9: Advanced |
| Author: | John Mark Osborne |
| SKU: | 33824 |
| ISBN: | 1-934743-32-1 |
| Release Date: | 2007-11-21 |
| Duration: | 10 hrs / 115 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 