Creating Exchange items

You can create Exchange events, contacts, and tasks by using the cfexchangecalendar, cfexchangecontact, or cfexchangetask tag, respectively, and specifying an action attribute value of create. You create mail messages by using the cfmail tag to send the message. For information on sending mail, see Sending and Receiving E-Mail.

When you create a calendar event, contact, or task, you specify the action, the connection information (persistent connection name or transient connection attributes) and an attribute that specifies a structure with the information you are adding. You can also specify a result variable that contains the value of the Exchange UID for the entry that you create. You can use this UID to identify the entry in tags that modify or delete the entry.

The name of the attribute that you use to specify the entry information varies with the tag you are using, as follows:

Tag

Attribute

cfexchangecalendar

event

cfexchangecontact

contact

cfexchangetask

task

Enclose in number signs (#) the variable that contains the details of the event, contact, or task data, as in the following example:

<cfexchangecalendar action="create" connection="myConn" event="#theEvent#" 
    result="resultUID">

The contents of the entry information structure depend on the tag. For details of the structure contents, see cfexchangecalendar, cfexchangecontact, and cfexchangetask in the CFML Reference.

Note: To create an Exchange calendar appointment, create a calendar event and do not specify any required or optional attendees.

The following example lets a user enter information in a form and creates a contact on the Exchange server with the information:

<!--- Create a structure to hold the contact information. ---> 
<cfset sContact="#StructNew()#"> 
 
<!--- A self-submitting form for the contact information ---> 
<cfform format="flash" width="550" height="460"> 
    <cfformitem type="html"><b>Name</b></cfformitem> 
    <cfformgroup type="horizontal" label=""> 
        <cfinput type="text" label="First" name="firstName" width="200"> 
        <cfinput type="text" label="Last" name="lastName" width="200"> 
    </cfformgroup> 
    <cfformgroup type="VBox"> 
        <cfformitem type="html"><b>Address</b></cfformitem> 
        <cfinput type="text" label="Company" name="Company" width="435"> 
        <cfinput type="text" label="Street" name="street" width="435"> 
        <cfinput type="text" label="City" name="city" width="200"> 
        <cfselect name="state" label="State" width="100"> 
            <option value="CA">CA</option> 
            <option value="MA">MA</option> 
            <option value="WA">WA</option> 
        </cfselect>  
        <cfinput type="text" label="Country" name="Country" width="200" 
                Value="U.S.A."> 
        <cfformitem type="html"><b>Phone</b></cfformitem> 
        <cfinput type="text" validate="telephone" label="Business" 
                name="businessPhone" width="200"> 
        <cfinput type="text" validate="telephone" label="Mobile" 
                name="cellPhone" width="200"> 
        <cfinput type="text" validate="telephone" label="Fax" name="fax" 
                width="200"> 
        <cfformitem type="html"><b>Email</b></cfformitem> 
        <cfinput type="text" validate="email" name="email" width="200"> 
    </cfformgroup> 
 
    <cfinput type="Submit" name="submit" value="Submit" > 
</cfform>  
 
 
<!--- If the form was submitted, fill the contact structure from it. ---> 
<cfif isDefined("Form.Submit")> 
    <cfscript> 
        sContact.FirstName=Form.firstName; 
        sContact.Company=Form.company; 
        sContact.LastName=Form.lastName; 
        sContact.BusinessAddress.Street=Form.street; 
        sContact.BusinessAddress.City=Form.city; 
        sContact.BusinessAddress.State=Form.state; 
        sContact.BusinessAddress.Country=Form.country; 
        sContact.BusinessPhoneNumber=Form.businessPhone; 
        sContact.MobilePhoneNumber=Form.cellPhone; 
        sContact.BusinessFax=Form.fax; 
        sContact.Email1=Form.email; 
    </cfscript> 
     
    <!--- Create the contact in Exchange ---> 
    <cfexchangecontact action="create"  
        username ="#user1#" 
        password="#password1#" 
        server="#exchangeServerIP#" 
        contact="#sContact#" 
        result="theUID"> 
         
    <!--- Display a confirmation that the contact was added. --->     
    <cfif isDefined("theUID")> 
        <cfoutput>Contact Added. UID is#theUID#</cfoutput> 
    </cfif> 
</cfif>

For another example of creating items, which creates a task, see Using transient connections.