Working with Records / Duplicating Records
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
In this lesson we're going to finish up our description and instructions on how to work with records via the API. As you can see, our actions are becoming quite simple now. Now that you understand what it takes to work with a record, edit a record and all the different validation options that are available, you can see that deleting and creating records are fairly straightforward and that's the way it is with the last command we'll cover, which works with records and that's the duplicate command. First of all, we're working in the 1207 folder now and let's go ahead and open the asset list page inside of our 1207 folder. Here you can see we have our delete button, which we created in our previous lesson and now in the next column over, we want to create a duplicate button. This will be fairly straightforward, just as simple as the delete command was. First we'll open up our asset list page inside of our code editor and let's go down to where we created our delete anchor tag. To keep things simple, we'll just copy this code and paste it in the column before that and change what needs to be changed for duplicating. First of all, our duplicate page is going to be called duplicate item.php and we're passing the rec ID so we have a complete href URL now for the anchor tag that we'll duplicate and then our media, instead of being del 12 is going to be dup 12 for duplicate. Let's ago ahead and view this now that we've made our changes and we have our duplicate icon. To make it look a hair bit better, let's go ahead and center it using a style and now we're ready to create our duplicate item.php. Notice that we need the record ID. So going to our code editor, let's go ahead and copy our include code and create a new file. After pasting it, we'll go ahead and save it in the 1207 and we'll call it duplicate item.php. Similar to deleting and adding, we just need to use the appropriate command found in the FileMaker API. Here we're going to be using the new duplicate command and we're going to pass the layout and the record ID so that it knows which record to duplicate. As with all the other commands, the duplicate command inherits from the FileMaker command the ability to do other methods during this action. Even though I'm not using these methods and we're going to be leaving working with the FileMaker commands, I want to reiterate the importance that you can use some of these methods. The ability to sort records, the ability to perform scripts and so forth before you duplicate a record and then after you duplicate a record can not be minimized. That creates a tremendous amount of power and functionality in your web application because you're able to implement a lot of pre-scribed FileMaker logic in your scripts and so forth. And being able to execute that logic before and after you perform these actions is a huge time saver when programming web applications. Then you don't have to recreate a lot of the logic again inside of your PHP code. So we're going to create our duplicate command and then we're going to execute it. Let's go ahead then and in our code editor create our variable duplicate and it's going to be equal to FM new duplicate command. We're going to pass the layout, which is web item detail and the record ID, which is coming to us in the get super global array. Once we have duplicated or created our duplicate command, we simply call its execute function and then we error check. Assuming everything's going well, now we want to go ahead and redirect the user back to the calling page, which is going to be the asset list.php and then, of course, after we redirect, we exit. Now, I know in a lot of these redirects there's no code afterwards, so what's the point of exiting because PHP exits as soon as the last function executes. Like I've mentioned in previous lessons, you always want to make sure you exit after you relocate the user or redirect the browser. The reason why we do this even though we know there's no code afterwards is because you never know when you or somebody else is going to come back and edit this page. All of a sudden there might be extra code that's added down underneath, maybe the duplicate option goes inside of condition statements and so forth. So it just plays it safe to go ahead and put your exit after your header and then you know that you've done your part. Let's go ahead and save this now and in our browser we'll duplicate a record. Let's refresh and make sure that we have our most current list and we'll duplicate this, uh, Acer Aspire L310. We click duplicate and we scroll down. We have our duplicate record here. So we can keep duplicating as much as we need and here you can see all our duplicate records. So really, we have a functioning list just as we would inside of FileMaker Pro. And of course, these records are representative of our data set inside FileMaker and now you can see we have a total of 47 records and when we scroll to the end, you can see our duplicated items. This concludes our chapter on working with records with the API and concludes our lesson on how to duplicate records with the new duplicate command object.
Tutorial Information
| Course: | FileMaker 9 & PHP Foundations |
| Author: | Lance Hallberg |
| SKU: | 33786 |
| ISBN: | 1-933736-99-2 |
| Release Date: | 2007-08-22 |
| Duration: | 9.5 hrs / 107 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
United States 