|
|
APPLICATION INTEGRATION
Manage Your Contacts: Import vCards into FileMaker Pro
Are your contacts getting out of control? Find out how to get all the valuable information from your vCards into a FileMaker Pro database.
DOWNLOAD (28,441 bytes) -- A fully functioning example of the vCard importer that uses a custom function and parses most of the common nodes and values.
UNLOCKED -- This article is provided to subscribers of FILEMAKER ADVISOR or DATABASED ADVISOR or FILEMAKER ADVISOR. To subscribe or renew, go to Advisor Store.
PAGE 1 of 1 - 2 - 3 - 4 - 5 - » Next
vCards are a handy way to pass contact information in a standard format. Although FileMaker Pro doesn't import them natively, with a little work, you can do it. The basic steps to importing vCards are: bring the vCard data into your database, do some pre-parsing work, and parse the card.

Figure 1: Specify Output File -- How to use a variable in the Export Field Contents "Specify" dialog.
If you'd like to follow along with the examples in this article, you'll need a table named vCardImporter with a text field called data, a global text field called peskyNull_g (choose the Auto-Enter - Data: option under Options, but leave the auto enter data field blank for now), and a global container field called vCard_g. Let's get started.
Bring the vCard data into your database
You might be wondering why you can't simply import a vCard into FileMaker Pro. Well, the ".vcard" and ".vcf" file extensions aren't recognized file formats for FileMaker Pro. Although you could manually change the extension in your file system every time you want to import a vCard, there's a more elegant solution.
Steps 1-3 prompt the user for a vCard, then export and rename it so you can import it as a .txt file. Step 4 imports the data from the renamed vCard as FileMaker Pro records, one record per line in the vCard.
- Start by creating a script titled Import. In it, add an Insert File script step to add the vCard to the global container field. Be sure to leave the Specify File option unspecified in the Insert File script step; it will cause FileMaker Pro to present the file open dialog to the user. For this technique, it doesn't matter if the user clicks on "Store only a reference to the file" in the file selection dialog, because Export Field Contents -- the script step you use to write the file out with a different name -- does its job the same way for a file stored in a container field, as well as a reference to a file on disk.
- Add a Set Variable script step to store the path and name you want to use to rename your vCard file. An easy way to get a valid path is to copy it out of a script step that offers a file reference dialog, such as Import Records, then change the name of the file to your temporary file name. Whatever file name you choose, you must make the file extension .txt. The example code shows how to specify a generic temporary file name. Remember, the value in this variable is just there to write out the vCard the user has chosen to a known location as a .txt file. You can remove the .txt file at the end of the process, or overwrite it every time you run the Import script.
- Add an Export Field Contents script step, referencing the container field that holds the vCard and the variable that holds the path and file name you want to use to rename the vCard. Beginning with FileMaker Pro 8, you can use variables to dynamically specify paths for script steps that have embedded file references (referred to as unnamed file references because you don't save these file references with the Define/Manage File Reference dialog, and you can't use them anywhere else in your application). The best approach is to initialize a script variable in a previous script step and insert the variable into the unnamed file reference dialog used by the script step. See the sidebar "Best Practices" for more information. Don't try to perform calculations in that file reference dialog, simply insert the variable (figure 1).
- Add an Import Records script step to import the records from the renamed file into the data field, entering $path in the Specify File dialog. Select "Perform without Dialog," because there is no need to show the dialog.
Tip: When you use a script variable to specify a path for the Import Records script step, you won't see any records in the Specify Import Order dialog. Why? Well, at the time you're editing your script, there is no value in your script variable, so FileMaker Pro can't find a file for you to use to work out your import order. Fortunately, there's an easy fix.
Sidebar: Best Practices
The best practice for exporting field contents with a dynamic path is to simply insert the variable into the Specify Output File dialog. You should handle all calculations to create the file name and path in the Set Variable [] script steps, not in the dialog. In the above example, $path includes the location of the file, as well as the name of the file. Prepend the value in the path variable with file: (or filewin:/filemac:, but in this example, file: works fine; it will as long as you aren't using FileMaker Server to host your file.
You use the Set Variable script step to get the correct value into $path:
Set Variable [$path; Value: "file:"&Get(DesktopPath)&"tmpCard.txt"]
Where …
"file:" is a hard-coded string you need before the path.
"Get(DesktopPath)" returns the absolute path the desktop, which is where you're going to drop your file.
"tmpCard.txt" is a hard-coded temporary file name.
On my computer, $path contains this after the Set Variable script step runs:
file: /Macintosh HD/Users/rjacques/Desktop/tmpCard.txt
PAGE 1 of 1 - 2 - 3 - 4 - 5 - » Next
Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro
ADVISORAMA The very essence of leadership is that you have to have a vision. You can't blow an uncertain trumpet. -- Theodore Hesburgh
|
ARTICLE INFO
Web Edition: 2008 Week 09, Doc #19417Print Edition: April/May 2008, Page 48
ARTICLE LOCKED
File: A fully functioning example of the vCard importer that uses a custom function and parses most of the common nodes and values.
DOWNLOAD: 28,441 bytes
|
FileMaker Advisor Sponsors
|

Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.![]() 
Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!![]()  ![]()
![]()

See exactly how to do it, step-by-step, in Advisor Academy CDs created by the top experts. Click to see what you can learn right now.![]() 
Keep up! Hot News, How-To, Tips & Tricks, Expert Advice, and more. Click to request your's free.![]()  ![]()

What direction are you going with your business? Advisor Guides are packed with the answers you need to work smarter. Can you afford to fall behind?![]() 
Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!![]()  ![]()
|
|