Home
Username:
Password:
FileMaker Pro 9: Intermediate Tutorials

Scripting / Inventory Control Subtract




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.


Learn More

Subtitles of the Movie

The second inventory script removes inventory from products as you sell each product. So we're going to need to go to invoices and we'll run this whenever we run the print invoice script. We'll remove, in this case, two Columbian and three Amaretto from products. So let's take a look at how that works. We come down here, look at print invoice and we go through and see what things are the same and what things have changed. So this is the same, still the same related record, the same sort, the same enter preview mode, same show custom dialog. This is the same all the way down here. It doesn't change until we get down here and we start off with an if statement. Now, this is a very important if statement because this determines whether we printed that invoice or not. Because you'll see the following script step says set the date printed field to the current date. So we can only get into this if statement once. In other words, each time, the only the first time we print that invoice. And that's important because we only want it to take out the inventory the first time we run this print script. And so if we take a look at this date printed field, we'll go into manage database. There's date printed. Just simply the date field. No options. This is auto-entering. Just a simple date field. So when you create a record it'll be empty and as we print, the first time we print, it will have the current date in there and this'll be false after that. Only when it's empty when we get in there. And then we'll freeze the window. Why? Because we're going to be looping and that always speeds things up on a loop. Because every time you loop from record to record or do any kind of loop, there's screen refresh and freeze window will stop that screen refresh and, in many cases, speed it up ten times as fast as it would have normally been. So it's always good to start a loop with a freeze window. Then we get into our loop and the first thing we do is say set field. Well, what record are we on? Where are we at right now? Well, if you remember, we did a go to related record up here and this said go to related record in invoices from lines. So it showed us all of the line items for that invoice. We never changed layout anywhere until here, so we're still on that layout, which means that since that layout is based on the lines table, that means that the lines table connects up to the products table, which means that from that line record that we're on at that moment, because we're in a loop going through records, we are looking at a particular product. So we're saying look at that inventory field. That's our target. Look at the products in that inventory field. So that line items relates to one product record and so we can identify that inventory field. And what are we going to do? Well, our calculation is going to reference inventory, so we keep the inventory we have in there inside the formula, but then subtract from lines what the quantity is. So if we have a hundred inside our inventory right now and we sold three, it's going to make it into 97. Then we say go to the next record. Now, you'll see this important option here, exit after last. This is another way to exit a loop. It only shows up in certain situations. Not on first record, not on last. Shows up on previous and it shows up on next. So what this says is once we get to the last record, we're going to set the field and it's going to say go to the next record. It's going to say there's no more records to go to. Then I'm going to exit. Then instead of having to do an exit loop if. So that's a very powerful way to loop here if you're going through records. You almost always use this option here and then once you're done, you end the loop and if and go back to the original layout. So let's see this in action. And if you remember, all of our products have one hundred inventory right now. So we want to look at Columbian, selling two, Amaretto, selling three. We'll hit print invoice, hit return. I'm not going to print the invoice but we'll still subtract from it. Let's go over to our products and we can walk through these and there's a Columbian, that's down to 98. And there's Amaretto, down to 97. So it worked perfectly for us. And if we come back here and run it one more time, so we'll say print invoice, same, same invoice, hit return, no, go back to products, we'll notice that it's still at 97 and the other one's still at 98. That's because we can only reduce the inventory once.

Tutorial Information

Course: FileMaker Pro 9: Intermediate
Author: John Mark Osborne
SKU: 33823
ISBN: 1-934743-30-5
Release Date: 2007-11-13
Duration: 10.5 hrs / 130 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
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available