fiogf49gjkf0d
In this article Thomas Außem shows how to easily create vCard files for SalesLogix contacts. Thomas not only demonstrates how to create vCard files, but also shows an excellent example of how to create and write to text files using the FileSystemObject.
One way to make yourself familiar with VBScript and COM is the using of the simplest COM object in your scripts - the FileSystemObject. I often use the FileSystemObject to create flat files from SalesLogix, e.g. to export the current group into a HTML file.
The function "CreateContact_VCard" demonstrates the using of the FileSystemObject in a simple way. It generates a simple flat file within the vCard format (Electronic Business Card), containing the contact's details.
The function returns TRUE if the vCard file was created successful and it expects a valid contactid as parameter.
Function CreateContact_VCard(sContactID)
Dim fso, fVCardFile, sFileName
Dim rs, sSQL
Dim sErrMsg
' check wether sContactID contains any data, if not leave the function
If Trim(sContactID) = "" Then
CreateContact_VCard = False
Exit Function
End If
' set the filename for the vcard-file
' USE THE FILE-EXTENSION .VCF !!!!
sFileName = "C:\temp\" & sContactID & ".vcf"
' errormessage if the file allready exists
sErrMsg = "File '" & sFileName & "' already exists." & chr(13)
sErrMsg = sErrMsg & "Would you like to overwrite the existing file?"
' create the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' check wether this file allreadz exists, if so, show a confirmation dialog
If fso.FileExists(sFileName) Then
If MsgBox(sErrMsg, vbYesNo,"") = vbNo Then
Set fso = Nothing
CreateContact_VCard = False
Exit Function
End If
End If
' generate the SQL statement to get all neccessary information for the vCard file
sSQL = "SELECT account,title,firstname,lastname,homephone,workphone,mobile,"
sSQL = sSQL & " fax,email,addressid,address1,postalcode,city,country "
sSQL = sSQL & " FROM contact,address WHERE CONTACTID = '" & sContactID & "'"
sSQL = sSQL & " AND contact.addressid = address.addressid"
' create a new ADO connection and invoke the SQL statement
Set rs = CreateObject("ADODB.Recordset")
Set rs.ActiveConnection = Application.GetNewConnection
rs.open sSQL
' open the file for overwriting
Set fVCardFile = fso.CreateTextFile(sFileName, True)
' write all information from SQL statement to the vCard file
fVCardFile.WriteLine("BEGIN:VCARD")
fVCardFile.WriteLine("VERSION:2.1")
fVCardFile.WriteLine("N:" & rs.Fields("LASTNAME").Value & ";" & _
rs.Fields("FIRSTNAME").Value)
fVCardFile.WriteLine("FN:" & rs.Fields("FIRSTNAME").Value & " " & _
rs.Fields("LASTNAME").Value)
fVCardFile.WriteLine("ORG:" & rs.Fields("ACCOUNT").Value)
fVCardFile.WriteLine("TITLE:" & rs.Fields("TITLE").Value)
fVCardFile.WriteLine("TEL;WORK;VOICE:" & rs.Fields("WORKPHONE").Value)
fVCardFile.WriteLine("TEL;WORK;FAX:" & rs.Fields("FAX").Value)
fVCardFile.WriteLine("TEL;HOME;VOICE:" & rs.Fields("HOMEPHONE").Value)
fVCardFile.WriteLine("TEL;CELL:" & rs.Fields("MOBILE").Value)
fVCardFile.WriteLine("EMAIL;WORK:" & rs.Fields("EMAIL").Value)
fVCardFile.WriteLine("ADR;HOME:;;" & rs.Fields("ADDRESS1").Value & ";" & rs.Fields("CITY").Value & _
";;" & rs.Fields("POSTALCODE").Value & ";" & rs.Fields("COUNTRY").Value)
fVCardFile.WriteLine("END:VCARD")
' close the file and set the FileSystemObject to nothing
fVCardFile.Close
Set fso = Nothing
rs.Close
Set rs = Nothing
End Function
This script was written in SalesLogix 6.2.
You can find detailed information about the vCard format on http://www.imc.org/pdi/
Detailed information about the FileSystemObject is available in the Microsoft VBScript documentation.
You may combine this script with the Stephen Redmond's article Using the SalesLogix Mail Client to Send E-mail, to attach a vCard file with contact detail information of the logged in SalesLogix user.