Filemaker | create vCard .vcf and carriage returns in text export

AIM:

To find a solution to create a vCard file from a Filemaker contact database – ideally natively with no plug-in. (vCard [.vcf] is a file format standard for electronic business cards. vCards are often attached to e-mail messages. They can contain name and address information, phone numbers, URLs, logos, photographs, and even audio clips.)

SOLUTION:

The first step was to map out the structure of a vCard to be able to replicate it into a filemaker field.

The following is an example of a vCard file containing information for one person:

BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
FN:Forrest Gump
ORG:Gump Shrimp Co.
TITLE:Shrimp Man
TEL;WORK;VOICE:(111) 555-1212
TEL;HOME;VOICE:(404) 555-1212
ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA 30314=0D=0AUnited States of America
ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA 30314=0D=0AUnited States of America
EMAIL;PREF;INTERNET:forrestgump@walladalla.com
REV:20080424T195243Z
END:VCARD

vCard defines the following property types: FN, N, NICKNAME, PHOTO, BDAY, ADR, LABEL, TEL, EMAIL, MAILER, TZ, GEO, TITLE, ROLE, LOGO, AGENT, ORG, CATEGORIES, NOTE, PRODID, REV, SORT-STRING, SOUND, URL, UID, VERSION, CLASS, KEY [1]. In addition, because vCard augments RFC-2425, a standard for directory information, the following property types are also supported: SOURCE, NAME, PROFILE, BEGIN, END.

This is fairly straight forward to map from a contact database in Filemaker via a calculation field but here is a custom function that wraps it all up nicely:

/* Returns text formatted as a vCard

This function takes contact info and formats it into the vCard format as text.  The result field contents can be exported and opened as a .vcf file which can be opened in the Apple Address Book and other software that supports the vCard format.

Written by Chris Pye – info@mactec.com.au

vcard ( FirstName; LastName; Org; Title; Phone; Fax; Mobile; Email; Street; Suburb; State; Zip; Country )

*/

// DECLARE VARIABLES

Let ( [

// All relevant fields are mapped here

_LastName = LastName;
_FirstName = FirstName;
_MiddleName =””;
_Title = Title;
_Suffix = “”;

_Org = Org;
_Dept = “”;
_JobTitle = “”;

_Phone1Value = Phone;
_Phone1Label = “work”;

_Phone2Value = Fax;
_Phone2Label = “fax”;

_Phone3Value = Mobile;
_Phone3Label = “cell”;
_Email1Value = Email;
_Email1Label = “work”;
_Address1Street = Street;
_Address1City = Suburb;
_Address1State = State;
_Address1Code = Zip;
_Address1Country = Country;
_Address1Label =”work”;

_FullName = FirstName & ” ” & LastName;

// I have had problems with bad characters in the street line, so added this
_FilterText = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-()/¶\’ []?,!#” & “‘”;

//
// NOW START FORMATTING THEM FOR THE VCARD FORMAT
//

vname = _LastName & “;” & _FirstName & “;” & _MiddleName & “;” & _Title & “;” & _Suffix;

vfname = _FullName;

vtel1 = If( not IsEmpty ( _Phone1Value );”TEL;” & If(PatternCount (_Phone1Label ;” ” )=1;Substitute ( _Phone1Label ; ” ” ; “;” );_Phone1Label) & “:” & _Phone1Value & “¶”;”” );

vtel2 = If( not IsEmpty ( _Phone2Value );”TEL;” & If(PatternCount (_Phone2Label ;” ” )=1;Substitute ( _Phone2Label ; ” ” ; “;” );_Phone2Label) & “:” & _Phone2Value & “¶”;”” );

vtel3 = If( not IsEmpty ( _Phone3Value );”TEL;” & If(PatternCount (_Phone3Label ;” ” )=1;Substitute ( _Phone3Label ; ” ” ; “;” );_Phone3Label) & “:” & _Phone3Value & “¶”;”” );
vmail1 = If( not IsEmpty ( _Email1Value);”EMAIL;INTERNET;” & LeftWords ( _Email1Label;1 ) & “:” & _Email1Value & “¶”;”” );
vad1 = If( not IsEmpty (_Address1Street); “ADR;” & _Address1Label & “:;;” & Filter(Substitute ( _Address1Street;”¶”;”\n”) ; _FilterText) & “;” & _Address1City & “;” & _Address1State & “;” & _Address1Code & “;” & _Address1Country & “¶”;””);
vorg = If( not IsEmpty (_Org);”ORG:” & _Org & “;” & _Dept & “¶”;””);

vtitle = If( not IsEmpty ( _JobTitle ); “TITLE:” & _JobTitle & “¶”;””)
// AND THE FINAL FORMATTING

];
“BEGIN:VCARD¶VERSION:2.1¶” &
“N:” & vname & “¶” &
“FN:” & vfname & “¶” &
vorg &
vtel1 & vtel2 & vtel3 &
vmail1 &
vad1 &
vtitle &
“END:VCARD”

)

However even if you use export field contents of a field using this custom function (or any for that matter) you get the paragraph returns wiped out (Windows and Filemaker 9.0v3 – I think on a Mac this is probably not the case – Windows needs CRLF or Carriage Return followed by a Line Feed and Mac only need the CR).

I first had a search through some forums for a solution as obviously without this I could not export the field to a vcf file format as the paragraph returns are very important in the make up of this file.

To export the file to another format I personally have used the Troi file plugin and using the CreateFile and  SetContents functions which basically creates a file (.vcf in this case) and then you set the contents of that new file to the field which is displaying the output of the custom function (of the contact you are on in the database). There is also an option to convert CR to CRLF on output for Windows users.

However the aim of this was to do it without a plugin.

Therefore to tackle this I have used and Export Records native function using FMPXMRESULTS on a XSL style sheet file – the example is below and works a treat:

filemaker_export_contents_vcf_text

This solution can be used to create more than just vcf format files and hope this comes in handy for anyone else looking at this and finding problems on Windows.

 

8 thoughts on “Filemaker | create vCard .vcf and carriage returns in text export

  1. Tyson

    THANK YOU! I had been beating at how to create .jnlp files out of my Filemaker database for DAYS… This was EXACTLY what I needed! And there’s so many other applications for it!

    Reply
  2. CS8

    Thank you very much for taking the time to share this. Without it I would have probably spent days trying to find a workaround to prevent carriage returns being stripped from my export file.

    Reply
  3. ajith murali

    Sir,
    I have to use vcard sms facility in my mobile.Please help me to find general codes for vcard sms,which can be used to send vcard sms from any mobile to any mobile.

    I have searched in google for help and got some codes,but that code is not working for all mobiles which support vcard facility.While searching I came to know about your comany.Hope you will have answer for my questions and help me.

    Yours Truely,
    AJITH MURALI.

    Reply
  4. Pingback: Neal & Associates » Blog Archive » Exporting to vCard from FileMaker

  5. Chuck Hutinger

    Most Excellent. I stored the xls file in a container field in it’s own table of one record with a relate all relation so it goes into my specified export records on other user’s machines when they grab vcf exports from our staff server. Then they can add since they have the xls file. Users are unaware. Thank you, thank you, thank you! Elegant solution!!!

    Reply
  6. Jean-Francois

    hoooo boy Thank you Wojtek, that just made my day… this is what I was looking for for years!!

    when exporting to plain text the LF and CR was always missing…. sometime we need a little help :)

    Now the export to create an ICS event file is working like a charm!

    thank you thank you thank you……

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *