Adobe COLDFUSION 9 Manual page 1288

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using External Resources
<cfcomponent>
<cffunction name="onIncomingMessage">
<cfargument name="CFEvent" type="struct" required="YES">
<!--- Remove any extra white space from the message. --->
<cfset message =Trim(arguments.CFEvent.data.MESSAGE)>
<!--- If the message is numeric, a previous search probably returned a
list of names. Get the name to search for from the name list stored in
the Session scope. --->
<cfif isNumeric(message)>
<cfscript>
if (structKeyExists(session.users, val(message))) {
message = session.users[val(message)];
}
</cfscript>
</cfif>
<!--- Search the database for the requested name. --->
<cfquery name="employees" datasource="cfdocexamples">
select FirstName, LastName, Department, Phone
from Employees
where 0 = 0
<!--- A space indicates the user entered a first and last name. --->
<cfif listlen(message, " ") eq 2>
and FirstName like '#listFirst(message, " ")#%'
and LastName like '#listlast(message, " ")#%'
<!--- No space: the user entered a first or a last name. --->
<cfelse>
and (FirstName like '#listFirst(message, " ")#%'
or LastName like '#listFirst(message, " ")#%')
</cfif>
</cfquery>
<!--- Generate andreturn the message.--->
<cfscript>
retrunVal = structNew();
retrunVal.command = "submit";
retrunVal.buddyID = arguments.CFEvent.data.SENDER;
//No records were found.
if (employees.recordCount eq 0) {
retrunVal.message = "No records found for '#message#'";
}
//One record was found.
else if (employees.recordCount eq 1) {
// Whitespace in the message text results in bad formatting,
// so the source cannot be indented.
retrunVal.message = "Requested information:
#employees.firstName# #employees.lastName#
#employees.Department#
#employees.Phone#";
}
//Multiple possibilities were found.
else if (employees.recordCount gt 1) {
//If more than ten were found, return only the first ten.
if (employees.recordCount gt 10)
{
retrunVal.message = "First 10 of #employees.recordCount# records";
Last updated 8/5/2010
1283

Advertisement

Table of Contents
loading

Table of Contents