View comments | RSS feed
Contents > Developing ColdFusion MX Applications > Writing and Calling User-Defined Functions > About user-defined functions PreviousNext

About user-defined functions

You can create user-defined functions, or UDFs (also known as custom functions), and use them in your application pages as you do standard ColdFusion functions. This lets you create a function for an algorithm or procedure that you use frequently, and then use the function wherever you need the procedure. If you must change the procedure, you change only one piece of code. You can use your function anywhere that you can use a ColdFusion expression: in tag attributes, between pound (#) signs in output, and in CFScript code. Typical uses of UDFs include, but are not limited to the following:

For information about selecting among User-defined functions, custom tags, and ColdFusion components, see Reusing Code in ColdFusion Pages.

Note: The Common Function Library Project at http://www.cflib.org is an open source collection of CFML user-defined functions.

To use a user-defined function, you define the function and then call it. Typically you define the function on your ColdFusion page or a page that you include. You can also define the function on one page and put it in a scope that is shared with the page that calls it. (For more information on UDF scoping, see Specifying the scope of a function.) You can also put commonly used functions on a single ColdFusion page and include it in your Application.cfm page.


Contents > Developing ColdFusion MX Applications > Writing and Calling User-Defined Functions > About user-defined functions PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


PartsExpress said on May 20, 2004 at 8:00 AM :
There seems to be a slight bug with UDF's.
This is how my code reads:
<launchdate>#MyUDF(now())#</launchdate>

The output comes out like this:
<launchdate> 2004-05-20T10:17:57-4:00</launchdate>

Notice the space between the > and the 2. The original code does not call for this whitespace. Even with Whitespace management turned on in the admin this space still appears. My current work around is to do this:
<cfset the_date = MyUDF(now())>
<launchdate>#the_date #</launchdate>
This results in the correct output of:
<launchdate>2004-05-20T10:17:57-4:00</launchdate>
No screen name said on Jul 14, 2005 at 9:51 AM :
I had this problem too. The way to solve it is by adding 'output=false' in your function:

<cffunction name="Myfunction" output="false" displayname="" hint="">

Not sure what output=true really does. Should just be default to false.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/udfs2.htm