Filemaker vCard export

This custom function will create a vCard file from a Filemaker database. The basis of this can also be used in a script to export multiple records as a single vCard file.

I created this function as simple and portable way of exporting vCards from any Filemaker solution. This function takes contact info and formats it into the vCard format as text. The result field can be exported as tab separated text and saved with the .vcf file extension which can then be opened in the Apple Address Book and other software that supports the vCard format.

Please note that you need to use the “Export Field Contents” script step to maintain the returns at the end of each line. Using export record will strip the returns, and the vcard file will not open.

You can also find this Custom Function on Brian Dunnings excellent site.

/* 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”

)

This entry was posted in Blog, Filemaker. Bookmark the permalink.

Comments are closed.