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.
When we started this chapter we were talking about Phone Formatting Recursion and we created a Custom function to recursively format phone numbers of any length and then we went off on a tangent to cover other types of Preferences because we included a Preference for phone formatting so that you could specify what phone formatting you wanted rather than having to modify the calculation, so we spent some time on that Preferences section but we're going to come back to our Phone Formatting Recursive function because there's a few problems with it and let's demonstrate. If we add a customer here you can see that it's already formatted the phone number even though there's nothing in there and that's really kind of confusing. It makes it difficult to use. And if we come in here and type in something like 123, which isn't the right number, it comes up and gives us an erroneous message that says it must have 7 or 10 digits. That's not correct; we're allowing any number of digits. And it formats it incorrectly. You can see it's added in some formatting here in addition to what it had. So it's completely wrong. We need to fix this. We need to make it so it's more dynamic, so it pays attention to that Recursive function and the Preferences and all that kind of stuff. So let's revert this record and we're going to go into Manage, Database. We'll find the phone field and we'll start with the Auto-Enter here. Go to the Auto-Enter section and let's change this. All we need is a Case statement here. Now, we're not modifying the Recursive Custom function because the things we're going to do can't be done inside of a Recursive Custom function and you'll see why in a second. We're going to type in not isempty open paren Self and then Length of Filter of Self quote 0123456789, just like we've done before. We're going to check the length of that and see if it equals the Length of Filter and we're going to go over to our OPTIONS Customers, double-click on phone format semicolon, we're going to keep only the pound signs, because that's the number of digits it should have, it's minus all that formatting that's in there. So, if there's something inside of the phone field, the Self and the Length of our numbers inside of that equal the Length of our Filter, just the pound signs, then we can go ahead and run the Recursion successfully, otherwise we want to return Self. Now there's two reasons. Self, if we don't put Self here it'll eliminate what they've typed in and, but more importantly, if we eliminate what we've typed in by not putting Self here and just having it result in nothing then Validation won't have anything to work on and tell them what went wrong, so these two have to work together. Auto-Enter happens before Validation so we have to make sure that works. So that's the formula for that. And let's come back in here real quick before I forget, why can't we do it inside our Recursion, our Custom function? Well, we only want this part to happen once. We only want it to check to see if it's empty or not and whether the length is correct or not. In fact, we can't even really check it in Recursion because it's going to be feeding in those parameters over and over by subtracting from that length of that number in the formatting and we won't be able to check this and see what length it is. We only want to check it once and it would really be impossible to do it because that value keeps changing and it will, after the first Recursion, it'll go ahead and fail because it's going to take off values from here, so we really can't do that. So we'll come into our Validation and fix this and we'll start with this message here. It's not accurate anymore and we can't be very accurate like we did inside our Auto-Enter by checking how long our, the format, how many pound signs we have in there. We can't do that because you can't put a calculation in here. But we'll revisit this later with Script Triggers. For right now we're going to put a very generalized message, something like: Phone numbers, or we'll say, The phone number entered has the wrong number of digits. That looks good. And then we'll go to our Validation formula, take a look at that. I'm going to change this. We're going to grab this and copy to the Clipboard and replace it right here and the reason for that is we don't have to check for 7 digits anymore, so we don't need this code. It's really kind of pointless to have this in here if you're not repeating the code over and over again. So we're going to go down to just this. We also have to check one other thing so let's go in there. We don't want to check against 10 we want to check against the values we have over here in our Auto-Enter, which is this right here. So we'll copy this, make it easy on ourselves, go over to our Validation and put that in there. And then we also want to check to see if it's empty or not. So isempty Self or the Length equals that and oops, I made a mistake there. So if it's empty don't validate or, if this equals this, in other words, the length of what we typed in equals the length of our phone formatting just like before, then don't validate, otherwise any other situation validate. So we're going to take this and copy this code to the Clipboard, come over to our other field, phone-s and paste it right in there. And then we'll come in here to our Auto-Enter, copy that and paste it to our phone-s, there we go and then we'll come back in here to our phone and get our Validation message, we'll copy that, and paste it into here. Well, it looks like we have everything. We'll double check it. I've got this new formula here, got the message, I've got this calculated value, it looks good. Now we can test it out and see if it works. We're going to add a new customer. You can see it hasn't automatically formatted already. I can type in 123, tab, or Commit the record. Phone number entered was the wrong number of digits. That's good. We'll hit No. You can see it hasn't formatted, it left what we have. We can go in and type in the rest of the digits and it formats correctly and doesn't require me to fill this one in. So now it works really great. It validates in the right situations and it Auto-Enters in the right situations. So this will complete our Phone Recursion Calculation by adding in some additional logic into the actual calculation, not into the Recursive Custom function.
| 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 |