Hi this is Matt at AppWorks with another best practice video, and today we’re going to be talking about search and how to perform a find a couple different methods to do that. 

So if we go into our script workspace, I’ve got a couple scripts set up here that do different things – actually they both do the same thing, which is find all of the invoices within a date range, which is basically all the ones from the last 30 days. So the two methods I’m talking about – one of them uses the perform find command with the specify request option where you have to click specify and kind of go down into it to find out what it does and the second method goes to enter find mode, set field and perform find, kind of mimicking the normal way you would do a manual search in FileMaker. This second method is by far the one I prefer and I’m going to talk about why.

First of all, let’s run the script. If we run the first example, we can see it comes down to 10 invoices. If we run the second one, we can see it comes down to the same ten. They do the same thing, there’s no speed difference at all between them. The difference is what you can see and how much work you have to do to change and make modifications to the script. Let’s say we want to amend our search and we only want to limit to find records where the invoice amount was greater than a certain dollar amount. If you want to use the method A here, where you have to perform find, you have to kind of go into it, so click on the gear, click on specify, click on the find request. Go to edit mode, add another line so you could choose scroll down in here and choose your field, which is a very small picker, to find the total. Put in your search criteria, and note here that you can’t actually use, this is not a FileMaker calculation, so if you wanted a calculation here, you’d have to actually define a variable and use that instead. In this case, which is a simple example, we’re just going to use that. Note also that when we’re looking at it, we can’t really see what it does. The only way we can know is by clicking pretty deeply in – 1, 2, 3 clicks to kind of see what is happening. If we run this, we’ll see that we get a smaller number of invoices, down to 7. 

Ok, let’s make that same change in the other one. In here all we have to do is, when we enter our find mode, we just have a new set field command. We get a much larger picker with typeahead for our total. And then choose our value right here in the variable. Greater than 1000. Don’t make any typos. In this case, because it actually is a calculation dialog, you have to put your > in quotes. Then your number, actually, either way will work. The nice thing is you can put a full calculation in here of a very detailed way that you want your search to work. I really like this because you can see directly what’s happening right in the same window, and if I run it, it gets the same result at the same time. 

So I would say that it’s a best practice to use this method, I think you get a lot more flexibility, it’s much easier to add things, like if you want to add a step that does an omit. If you want to find all the ones where the status doesn’t contain the word, you know, sent, or something like that. You can just put omit record right after it, but not omit multiple, just plain omit record, so that is very easy to see. I, of course, would need a new request for that. You can see at a glance exactly what this script is doing, whereas if you use the other method, you have to really kind of go digging to find out what it does. Thanks very much for your time.