Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, March 29, 2024 
 
Using FileSystemObject to Create a vCard File  
Description:  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.

Category:  SalesLogix VBScript Articles
Author:  Thomas Aussem
Submitted:  11/24/2005
   
Stats: 
Article has been read 47249 times

Rating: - 5.0 out of 5 by 3 users
 

fiogf49gjkf0d
Using FileSystemObject to Create a vCard File

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.

Introduction

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.


Script

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


Additional Information

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.

 

About the Author

  Thomas Aussem
openCRMS

fjrigjwwe9r1SiteUser:UserBio
fiogf49gjkf0d

Working with SalesLogix 6.2 since December 2004 You'll find my German blog (that deals with SalesLogix, SQL Server and web development) on http://www.opencrms.de



View online profile for Thomas Aussem
 

[ back to top] [ send to a friend]  

Rate This Article you must log-in to rate articles. [login here] 
 
Please log in to rate article.
 

Comments & Discussion you must log-in to add comments. [login here] 
 
Author Article Comments and Discussion
Paul Pacun



Re: Using FileSystemObject to Create a vCard File
Posted: 4/26/2006 10:27:44 PM
fiogf49gjkf0d
Thanks..

We are going to write an app which will gather all of the vcards in a folder and import them all at once. The fun part will be parameterizing it so we can mark the contacts accordinly + deduping. Harvesting names is fun!!

Paul
 
 

       Visit the slxdeveloper.com Community Forums!
Not finding the information you need here? Try the forums! Get help from others in the community, share your expertise, get what you need from the slxdeveloper.com community. Go to the forums...
 



 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 3/29/2024 1:10:15 AM