Using the Contact APIs

See the Contact Functions to understand these

Creating contacts

<cfinclude template="/CFIDE/cfclient/useragent.cfm">
<cfclientsettings enableDeviceAPI=true>

<cfclient>
 
<cfset res = cfclient.contacts.create('Joe','1234567890','joe@mycompany.com',true)>
<cfset document.getElementById('result').innerHTML="Options object: #JSON.stringify(Object.keys(res))#"> 

</cfclient>

<div id="result"/>

Adding fields to the contact

<cfinclude template="/CFIDE/cfclient/useragent.cfm">
<cfclientsettings enableDeviceAPI=true>

<cfclient>

<cfset res.addPhoneNumber("5678234","work",true)>
<cfset res.addEmail("joe@gmail.com","home",true)>
 
<cfset cntadr=cfclient.contacts.createAddress("First street", "North", "Indian", "India","12345", "Good address form", "home", "true")>
<cfset res.addAddress(cntadr)>
 
<cfset cntorg=cfclient.contacts.createOrganization("SciTech", "Science", "Science Technology", "Education","true")>
<cfset res.addOrganization(cntorg)>

<cfset res.addIm("myIMHandle","home",true)>

<cfset res.addCategory("Friends","home",true)>
<cfset res.addURL("www.joe.com","home",true)>
<cfset res.addPhoto("myDir/img.jpg","home",true)>
 
<cfset cfclient.contacts.save(res)>

</cfclient>

Finding a contact

<cfclientsettings enableDeviceAPI=true>
<cfclient>
 
<!--- Searching all fields --->
<cfset cntlst=cfclient.contacts.find("Joe",["*"])>
 
<cfset document.getElementById('result').innerHTML=document.getElementById('result1').innerHTML+"Number of contacts - #arrayLen(cntlst)#"> 
<cfscript>
for (i = 1; i <= #arrayLen(cntlst)#; i = i + 1) {
writeOutput("<br><br>");
writeOutput(iter(cntlst[i])); 
} 
</cfscript>
 
<!--- Searching only the displayName field --->
<cfset cntlst=cfclient.contacts.find("Joe",["name","displayName"])>
 
<cfset document.getElementById('result').innerHTML=document.getElementById('result2').innerHTML+"Number of contacts - #arrayLen(cntlst)#">

<cfscript>
for (i = 1; i <= #arrayLen(cntlst)#; i = i + 1) {
writeOutput("<br><br>");
writeOutput(iter(cntlst[i])); 
} 
</cfscript>


<!--- Searching in the displayName and phoneNumbers fields --->
<cfset cntlst=cfclient.contacts.find("user1_1",["phoneNumbers,displayName"])>
<cfset document.getElementById('result').innerHTML=document.getElementById('result3').innerHTML+"Number of contacts - #arrayLen(cntlst)#">
<cfscript>
for (i = 1; i <= #arrayLen(cntlst)#; i = i + 1) {
writeOutput("<br><br>");
writeOutput(iter(cntlst[i])); 
} 
</cfscript>

</cfclient>
 
<div id="result1"/>
<div id="result2"/>
<div id="result3"/>

Getting all the contacts

<cfclientsettings enableDeviceAPI=true>
<cfclient>
 
<cfoutput>Getting all contacts</cfoutput>
<cfset cntlst=cfclient.contacts.getAllContacts(["*"])>
<cfset document.getElementById('result').innerHTML=document.getElementById('result3').innerHTML+"Number of contacts - #arrayLen(cntlst)#">
<cfscript>
for (i = 1; i <= #arrayLen(cntlst)#; i = i + 1) {
writeOutput("<br><br>");
writeOutput(iter(cntlst[i])); 
} 
</cfscript>
 
<cfoutput>Getting only the phone numbers</cfoutput>
<cfset cntlst=cfclient.contacts.getAllContacts(["phoneNumbers"])>
<cfset document.getElementById('result').innerHTML=document.getElementById('result3').innerHTML+"Number of contacts - #arrayLen(cntlst)#">
<cfscript>
for (i = 1; i <= #arrayLen(cntlst)#; i = i + 1) {
writeOutput("<br><br>");
writeOutput(iter(cntlst[i])); 
} 
</cfscript>

<cfoutput>Getting only the display names and phone numbers</cfoutput>
<cfset cntlst=cfclient.contacts.getAllContacts(["phoneNumbers,displayName"])>
<cfset document.getElementById('result').innerHTML=document.getElementById('result3').innerHTML+"Number of contacts - #arrayLen(cntlst)#">
<cfscript>
for (i = 1; i <= #arrayLen(cntlst)#; i = i + 1) {
writeOutput("<br><br>");
writeOutput(iter(cntlst[i])); 
} 
</cfscript>


</cfclient>

Get help faster and easier

New user?