My.ADVISOR.com Sign-In
Username
Password
Sign Up 
Go to Article
Advanced Search 

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.
By Roger Jacques, Soliant Consulting

UNLOCKED -- This article is provided to subscribers of FILEMAKER ADVISOR or DATABASED ADVISOR or FILEMAKER ADVISOR. To subscribe or renew, go to Advisor Store.

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.

  1. 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.
  2. 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.
  3. 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).
  4. 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

What do YOU think about this topic? Share your advice and thoughts using this form.

Your Name

REQUIRED : PUBLIC

Your E-Mail

REQUIRED : PRIVATE

Job, Company

OPTIONAL : PUBLIC

City, State, Country

OPTIONAL : PUBLIC

Your Web Site

OPTIONAL : PUBLIC

Your Comment

Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

Printer-friendly
page layout

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

FileMaker Advisor

Web Edition: 2008 Week 09, Doc #19417

Print Edition: April/May 2008, Page 48

SUBSCRIBER ONLY 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

Subscribe to FileMaker Advisor Magazine

Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

FileMaker.Advisor.com

Subscribe to Advisor Basics of FileMaker Pro

Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

FileMaker.AdvisorBasics.com

Secrets Of The Top Experts -- 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.

AdvisorAcademy.com

Free E-Newsletters

Keep up! Hot News, How-To, Tips & Tricks, Expert Advice, and more. Click to request your's free.

AdvisorUpdate.info

Need Know-How Now?

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?

AdvisorStore.com

Showcase Your Smarts

Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!

AdvisorTips.com

Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
Portions copyright ©1983-2008 Advisor Media, Inc. All Rights Reserved.
Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, Inc. in the United States and/or other countries.
Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
jacqr002 posted 02/25/2008 modified 05/12/2008 03:43:58 AM ztfmfd/ztfmfd
domino-144.advisor.com my.advisor.com 05/16/2008 12:31:47 PM