Identifying And Checking For Udfs - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

For example, the following code defines a function to combine a single first name and last name
to make a full name. It queries the CompanyInfo database to get the first and last names of all
employees, then it uses a
row in the query.
<cfscript>
function FullName(aFirstName, aLastName)
{ return aFirstName & " " & aLastName; }
</cfscript>
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName
FROM Employee
</cfquery>
<cfoutput query="GetEmployees">
#FullName(FirstName, LastName)#<br>
</cfoutput>
You generally use functions that manipulate many rows of a query outside tags that loop over
queries. Pass the query to the function and loop over it inside the function. For example, the
following function changes text in a query column to uppercase. It takes a query name as an
argument.
function UCaseColumn(myquery, colName) {
var currentRow = 1;
for (; currentRow lte myquery.RecordCount;
currentRow = currentRow + 1)
{
myquery[colName][currentRow] =
UCase(myquery[colName][currentRow]);
}
Return "";
}
The following code uses a script that calls the
in the GetEmployees query to uppercase. It then uses
display the contents of the column.
<cfscript>
UCaseColumn(GetEmployees, "LastName");
</cfscript>
<cfoutput query="GetEmployees">
#LastName#<br>
</cfoutput>

Identifying and checking for UDFs

You can use the
The
IsCustomFunction
you must ensure that the name exists before calling the function, for example, by calling the
function. The following code shows this use:
IsDefined
<cfscript>
if( IsDefined("MyFunc"))
if( IsCustomFunction( MyFunc ))
WriteOutput("MyFunc is a user-defined function");
else
WriteOutput("Myfunc is defined but is NOT a user-defined function");
else
tag to loop through the query and call the function on each
cfoutput
function to determine whether a name represents a UDF.
IsCustomFunction
function generates an error if its argument does not exist. As a result,
function to convert all the last names
UCaseColumn
to loop over the query and
cfoutput
Using UDFs effectively
209

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents