Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Let's discuss a new approach to marking duplicate records. We'll start by reminding you that Loops and Replace Field Contents can often substitute for each other, and Replace Field Contents is generally twice as fast as a record loop, so that's a good thing, but the substitution will only work in this scenario because we are just trying to place a value on a record. If we need other steps, such as, let's say, Delete Record or Omit Record a loop is really your only choice, but Replace Field Contents will work great here because we're only trying to replace and put a value into this duplicate field. So let's go ahead and add the components we need for this. In order for this Replace Field Contents feature to work we need a relationship, so we'll go to Manage, Database, go to the relationships and we'll add a New Table Occurrence for CUSTOMERS underscore Dups and we're going to connect it right into this one and if you notice if we try scrolling down it's a ways to go to find the dup check field. Let's say we're back up at the top here and this one we'd have to open up but let's say we don't want to open it up. I just drag to any two fields, if I can make sure I can get these connected there, there we go and make sure you can see the equal sign, double-click on it and then use the Type Ahead which is much faster. See how fast we can set up this relationship without having to open up and toggle this and do that kind of stuff? So, that's a, you know, a little tip to make things faster. So I'll move down here and put this one down here so we can see everything. That looks pretty good. And before we write the script let's take a look at what that's done for us. What we're going to do is come in here and add a field in here. I'm going to drag one over here, I'm Option-dragging it, or if you're on Windows Ctrl-drag it and we're going to put in the customer ID, there we go, come up here and find kp customers ID without that Label and we'll put that one right in about here and make it a little bit smaller and then we'll Option-drag another copy right over here, and I got it pretty good there, but this time from CUSTOMER Dups we'll choose customer ID. So we'll see how that works out. Let's go into Browse Mode and you can see that sometimes they match and sometimes they don't. To really understand how this works we need to make sure it's sorted and I believe it is right now, but let's double check. And it is sorted by Dup Check, which is great. So now we can see that Billy Adlington, his two records have 3 and 144. Those are the real values for that Customer, the real Customer ID. But on the related version we have 3 on both of them and if we scroll down and find some other duplicates you'll see the same thing happening. Here's Bob Wilford. You can see that it's 43 on each one of these, even though the other ones are different. Only the first one is represented on each one through that relationship and the reason for that is because when you're looking through a relationship and there's multiple related records and you don't put that related field inside a Portal it displays the first record, or first related record based on creation order. It has to make a choice so it chooses the first one. So you can actually change this if you want. Let's take a look at this on Billy Adlington. The first record's on 2-12-2010 and this one's on 4-28, so it's obvious it chose this one to repeat on there but we can switch that if we want. All we have to do is go to Manage, Database, double-click on that equal sign and do like we did before, which is Sort the records. We need to make sure we're on this side here, come find timestamp create, move it over and then sort it in Descending order. And now what you'll see is that you're going to have 144 on each of the records. So we've interrupted that creation order that FileMaker usually displays things in and substituted it with that Sort Order, and so now you can do it either way. You can either keep the first one made or keep the last one made, whichever you want. But now we can go ahead and take a look at the script. So we go into Manage Scripts, we'll click New, we'll call this Mark Duplicates Replace. There we go. And we can do all that stuff with turning on Allow User Abort, but I want to really show you how easy, or how short this script is. Just one step, Perform without dialog, Specify target field, that will be our Duplicate field and then we need a formula, so we have to use the concept from that self-joined relationship we made to make this work, so we're going to say Case CUSTOMERS kp customers ID does not equal, okay and you actually could use the not equal sign here but I like typing in - it's easier to type than figure out that keyboard command - not equal to CUSTOMERS Dups and there we go. When those don't equal each other we're going to say give us an x on that record, otherwise use the default, which is blank. So that's pretty cool how that works. We'll click OK, we'll click OK, now one thing you do need to realize about this short script is it does require that you not do that exclamation search because a relationship by nature always looks outside the Found Set so searching for that exclamation point won't help you at all anyhow. So, it'll actually outside of that and, you know, you can't confine it, even though it may not matter it won't confine it just to that Found Set so you have to understand the difference between these two methods. And, also, but and this is really a positive, maybe the other one's a positive, you never know. It all depends. I mean, you've got to understand how relationships work. Sometimes you want to be able to look outside the Found Set, sometimes you don't. It's a determination on which technique you use, but certainly a plus is we don't have to sort the database and if you're looking through a lot of duplicates we don't actually have to have this sorted so we're going to actually unsort it. There we go. And then we can run that script. And one benefit, also, here is that we don't have to unmark these values, remember? The default is blank. It'll actually blank out the ones that aren't supposed to be there. So that's kind of cool there, too. So let's go ahead and run this and it's all done and now really to look at it we're going to have to sort the records so we can see what it looks like and see what it did. You can see here now it's marked the oldest one for deletion and not marked the one that is actually the one that we want to keep, the newest one. And remember they were in reversed order before so it actually blanked out this one and added the x here, so that's kind of cool how that worked, how we didn't have to sort it and we didn't have to unmark them, so there's advantages and disadvantages in both techniques here. One other disadvantage you have to understand about relationships is they are kind of slow. Generally, if you're going through non-related records, you know, you're setting fields and you're not checking these relationships, you know, you're not doing anything with the relationship things are going to be faster in general. I can't say for sure always but I want to put that in your ear and make sure you understand that you probably want to test this and if speed's a real issue then you might want to consider this method. It might not be as fast as a looping method, especially on a lot of records.
| Course: | FileMaker Pro 11: Advanced |
| Author: | John Mark Osborne |
| SKU: | 34140 |
| ISBN: | 1-936334-36-4 |
| Release Date: | 2010-07-09 |
| Duration: | 14.5 hrs / 159 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |